← All courses

Animations

🗓 May 31, 2026 ⏱ 1 min read

Implicit animation

@State private var expanded = false

VStack {
    Rectangle()
        .frame(height: expanded ? 200 : 80)
        .animation(.spring(), value: expanded)
    Button("Toggle") { expanded.toggle() }
}

Explicit animation

Button("Like") {
    withAnimation(.easeInOut(duration: 0.3)) {
        liked.toggle()
    }
}

Transitions

if showDetail {
    DetailView()
        .transition(.move(edge: .bottom).combined(with: .opacity))
}
Tip: Animate a specific value with .animation(_, value:) rather than animating everything — it’s more predictable.