Applying a delay to a withAnimation function to create a sequence of animations
As we mentioned in the previous recipe, SwiftUI doesn't have a way to define a chain of animations yet, but this can be simulated using delay animations.
As mentioned in the previous recipe, there are two ways of defining an animation:
- Using the
.animation()
view modifier - Using the
withAnimation
function
In this recipe, we'll see how to use the withAnimation
function. We covered the .animation()
view modifier in the previous recipe, Applying a delay to a view modifier animation to create a sequence of animations.
Getting ready
This recipe doesn't need any external resources, so let's just create a SwiftUI project called DelayedAnimations
.
How to do it…
To illustrate the delay applied to the withAnimation
function, we are going to implement an app that presents three text elements that appear and disappear in sequence when tapping on a button: