|
I have a View where I use a Picture(image) subview to display an image, which can come in different height and width formats . The reference to the image is extracted from an array, which allows me to display different images in my View, by varying the reference. I would like an animation on this image, say a scale effect, when the image is displayed If I use onAppear(), it is called and performs the scale effect, but only once, on the first image of the array, at the first call of the View . If I use a Picture(image).scaleEffect(scale).animation() I have an an animation between the first and the second image , varying accordingly height and width which is ugly (and deforms aspectRatio) If I try Picture(image.animation()) it does not compile. How can I limit the animation to the scaling effet, and not to the image variation ? |
|
Hopefully this helps with one part of your problem. |
|
Actually no, as far as I can see. The problem I have is not to impose aspectRatio to my 2 images. They both are correct; It is the animation from one to the other which is buggy. i would like to replace the second one with the first, with no animation, then animate the second with a scale effect. I haven't found so far how to separate the two phases in SwiftUI. |
|
I put some code to formalize my problem. I have two images, star and circle. When I clicked on "tap me" the images are updated. What I would like: that the animation only animates the new image. i.e the star replaces the circle, then grows. And if I click again, the circle replaces the star then grows. It doesn't work.
|
|
Is this what you were looking for?
|
|
The short answer is Yes ! Thank you so much The long answer is
P.S : (this code does not compile in my playground: error: MacPlayground.playground:5:12: error: 'init(systemName:)' is unavailable in macOS let star = Image(systemName: "star.fill").resizable().aspectRatio(contentMode: .fit) And it does not either in the canvas "Property definition has inferred type 'some View', involving the 'some' return type of another declaration" but it works with real images, once the .resizable().aspectRatio(contentMode: .fit) put back in the Picture struct I put it back below for anyone interested )
|
|
Thank you for the PS @HugoInParis. I was playing on my IPad. I will try to take out machine/OS specific stuff in future. Keep up the good work! |
|
Finally I decided to put the needed code in the other view. It feels awkward to put in view B code to animate view A when both are never present at the same time, but it works |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.