0PricingLogin
SwiftUI Academy · Lesson

Explicit Animations with withAnimation

Wrap state mutations to control timing.

When You Want Control

Sometimes you want to decide exactly which change animates. withAnimation wraps a state change so its results tween.

The withAnimation Block

You put your state mutation inside withAnimation. Every view update caused by that change animates together.

withAnimation {
    isExpanded.toggle()
}

All lessons in this course

  1. Implicit Animations
  2. Explicit Animations with withAnimation
  3. Insertion & Removal Transitions
  4. Spring & Custom Timing Curves
← Back to SwiftUI Academy