Sequential animation?

Is sequential animation possible in SwiftUI? As in do animation 1, when finished do animation 2, etc.


I understand that SwiftUI is basically UI based off state, so if I could just get a notification when my an animation ends or if be able to tack on a closure to an animation to be called when an animation ends, I feel like I could set up my sequential animation. I'm not seeing any way to do either of these things though, anyone have any luck in this area?

Replies

I created a background image "carousel" using exactly the strategy you hinted at. I have three @State variables: one is an index to a list of images, one is the selected image name and the third indexes between the two Image views. On the closure of each transition I increment the image index, set the image name on the "hidden" image view, then flip the Image view index. The "old" image slides off and the "new" image slides on.

Whilst I’m not sure this would be a recommended solution. I’ve been playing with something similar using a property change to trigger an animation in a action closure. The view is configured to animate on property change; I use an action block on a Button to change the property (which triggers the basic view animation, then following the change of the property use a withAnimation. This results in the property animation followed by the separate animation from the withAnimation block.... kind of gives the required result because the withAnimation is starts a new animation transaction.