MΓ³dulo 06 Β· The HUD Design System β LecciΓ³n 4 de 4 Β· ~9 min
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:.linearmoves robotically evenly,.easeInstarts 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.autoreversesdecides the loop style:trueplays it backwards to return (breathing in, breathing out);falsesnaps back to the start and plays forward again (a radar sweep, always outward).