
SwiftUI Cookbook
By :

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:
.animation()
view modifierwithAnimation
functionIn 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.
This recipe doesn't need any external resources, so let's just create a SwiftUI project called DelayedAnimations
.
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: