Implicit vs Explicit Animations
Using .animation() modifier vs withAnimation {} block for different use cases.
Two Animation Styles
SwiftUI supports implicit animations (the .animation modifier) and explicit animations (the withAnimation closure).
struct Demo: View {
@State private var scale = 1.0
var body: some View {
Circle().scaleEffect(scale)
}
}Implicit Animation with .animation
Attaching .animation(_:value:) to a view animates it whenever the bound value changes.
Circle()
.scaleEffect(scale)
.animation(.easeInOut(duration: 0.3), value: scale)