SwiftUI toggle & switch animations

4 examples. Toggle & switch animations built with SwiftUI. Switches and toggles with satisfying knobs, colour fades, squash-and-stretch and theme changes.

SwiftUI toggle & switch animations: common questions

How do I build toggle & switch animations in SwiftUI?
Pick an example below, copy its prompt (or send it to Claude Code, Cursor or Codex) and your agent builds it in SwiftUI. Each prompt lists the layout, timing and easing, and links a keyframe sheet of the motion. Use withAnimation with a spring, for example .spring(response: 0.35, dampingFraction: 0.8), for most state changes. Reach for matchedGeometryEffect when an element moves between views, PhaseAnimator or KeyframeAnimator for multi-step sequences, and contentTransition(.numericText()) for changing numbers.
How do I animate a toggle switch?
Move the knob with a spring, stretch it slightly in the direction of travel while moving, and cross-fade the track colour. Keep it under 300 ms.
Should a toggle animate the whole page?
Only for theme switches. Otherwise keep the motion inside the control so it stays fast and predictable.

Toggle & switch animations in other frameworks

More SwiftUI animations