A Taste of Animation

You don't animate views β€” you animate change

Here's SwiftUI animation in one sentence: change some state inside withAnimation { … }, and SwiftUI smoothly plays the difference instead of jumping. You already know the first half β€” flip a @State value and the view re-renders. Wrapped in withAnimation, that re-render becomes a movie: every affected value (scale, opacity, position…) glides from old to new.

withAnimation takes an animation description saying how to glide:

  • .easeOut(duration: 1.9) β€” an easing curve: start fast, slow to a gentle stop, the whole trip taking 1.9 seconds. (Its siblings: .linear moves robotically evenly, .easeIn starts slow.) Ease-out is right for a radar ping β€” it bursts outward, then dies away.
  • .repeatForever(autoreverses: false) β€” chain this on and the animation replays endlessly. autoreverses decides the loop style: true plays it backwards to return (breathing in, breathing out); false snaps back to the start and plays forward again (a radar sweep, always outward).