Animating flower petals in an arc
We have a background, text labels, and an inhaling and exhaling breath effect; now let’s add the petals to the scene. We can add the petal code in a separate file, so press Command + N to bring up the New File window, and create a new SwiftUIView file called PetalView
.
The goal here is to make five petals move in an arc, so they open and close. We only need two variables for this, so this will be a very small file: we need one Boolean (Bool
) variable to track the animation, and another variable to hold the number of rotations we want for each petal. Let’s add them now:
@Binding var petal: Bool var degrees: Double = 0.0
The Binding
variable called petal
will handle the animation. We are using the Binding
wrapper because we are in a new struct, and we will need to use this variable in another struct, ContentView
. When we prefix a variable with the Binding
wrapper, we can then use...