delay(_:)
Delays the start of the animation by the specified number of seconds.
Declaration
func delay(_ delay: TimeInterval) -> AnimationParameters
- delay:
The number of seconds to delay the start of the animation.
Return Value
An animation with a delayed start.
Discussion
Use this method to delay the start of an animation. For example, the following code animates the height change of two capsules. Animation of the first Capsule begins immediately. However, animation of the second one doesn’t begin until a half second later.
struct ContentView: View {
@State private var adjustBy = 100.0
var body: some View {
VStack(spacing: 40) {
HStack(alignment: .bottom) {
Capsule()
.frame(width: 50, height: 175 - adjustBy)
.animation(.easeInOut, value: adjustBy)
Capsule()
.frame(width: 50, height: 175 + adjustBy)
.animation(.easeInOut.delay(0.5), value: adjustBy)
}
Button("Animate") {
adjustBy *= -1
}
}
}
}