Back to Swift Reference Ask BeeAI
📱 SwiftUIBeginneriOS 13+ · phase/keyframe iOS 17+
Animations & Transitions
Animate state changes with withAnimation, springs, transitions and symbol effects.
Wrap a state change in withAnimation to animate every view affected by it. Use .transition to control how views are inserted and removed.
Springs (.spring, .bouncy, .snappy) feel native on Apple platforms and are the recommended default.
animation.swift
1struct LikeButton: View {
2 @State private var liked = false
3
4 var body: some View {
5 Button {
6 withAnimation(.bouncy) { liked.toggle() }
7 } label: {
8 Image(systemName: liked ? "heart.fill" : "heart")
9 .font(.largeTitle)
10 .foregroundStyle(liked ? .red : .secondary)
11 .scaleEffect(liked ? 1.2 : 1)
12 .symbolEffect(.bounce, value: liked)
13 }
14 }
15}Common pitfalls
- Respect Reduce Motion: check @Environment(\.accessibilityReduceMotion) for large movements.
Still unclear? Ask BeeAI about Animations & Transitions.
Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.
Related topics
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans