I have an imageview in SwiftUI and i want to scale the view to higher size for fraction of second and return to it's normal size. How can i do this in SwiftUI?
Image("disagreeSmall")
.scaleEffect(scale)
.animation(.easeIn(duration: 0.15), value: selectedRating)
If you are able to use functionality that was only introduced in iOS 17 then there are two easy ways to achieve this animation:
1. Use a
.symbolEffect
The
.bounce
effect scales up and then down again:2. Add a completion callback to the animation
Use an animation to scale up, then when it completes, perform another animation to scale back down.
If you need to support older iOS versions then you could use other mechanisms to achieve a completion callback. This is how it could be done using the animation completion callback outlined in the answer to SwiftUI withAnimation completion callback: