Applying a delay to a withAnimation function to create a sequence of animations
As mentioned in the previous recipe, since the introduction of SwiftUI with iOS 13 there have been two ways of defining an animation:
- Using the .animation(_:value:) view modifier
- Using the withAnimation(_:_:) function
In this recipe, we'll see how to use the withAnimation(_:_:) function. We covered the .animation(_:value:) 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:
- To add a nice look, define a custom modifier for Text:
struct CustomText: ViewModifier {
let foreground...