23.7 Adding Rotation and Animation
The next step is to add the rotation and animation effects to the Text view using the value stored by the Slider (animation is covered in greater detail in the “SwiftUI Animation and Transitions” chapter). This can be implemented using a modifier as follows:
.
.
Text("Hello, world!")
.font(.largeTitle)
.fontWeight(.heavy)
.rotationEffect(.degrees(rotation))
.
.
Note that since we are simply reading the value assigned to the rotation state property, as opposed to establishing a binding, the property name is not prefixed with the ‘$’ sign notation.
Click on the Live Preview button (indicated by the arrow in Figure 23-8), wait for the code to compile, then use the slider to rotate the Text view:
Figure 23-8
Next, add an animation modifier to the Text view to animate the rotation over 5 seconds using the...