repeatForever(autoreverses:)
Repeats the animation for the lifespan of the view containing the animation.
Declaration
func repeatForever(autoreverses: Bool = true) -> AnimationParameters
- autoreverses:
A Boolean value that indicates whether the animation sequence plays in reverse after playing forward.
Return Value
An animation that continuously repeats.
Discussion
Use this method to repeat the animation until the instance of the view no longer exists, or the view’s explicit or structural identity changes. For example, the following code continuously rotates a gear symbol for the lifespan of the view.
struct ContentView: View {
@State private var rotationDegrees = 0.0
private var animation: Animation {
.linear
.speed(0.1)
.repeatForever(autoreverses: false)
}
var body: some View {
Image(systemName: "gear")
.font(.system(size: 86))
.rotationEffect(.degrees(rotationDegrees))
.onAppear {
withAnimation(animation) {
rotationDegrees = 360.0
}
}
}
}