Lecture 6: Animation

Animation was the topic of lecture 6 of Stanford Spring 2020’s iOS Application Development course. After covering some ancillary topics like local, ephemeral state in Views (@State) and property observers, the lecture goes into a deep dive on animation, including implicit vs. explicit animations, transitions, Shape animations, animating ViewModifiers and more. These concepts are then installed in the Memorize demo by animating the flipping of cards, creating a new game and giving bonus points for quick matches.

In SwiftUI, any changes to ViewModifiers or Shapes can be animated. Views can animate changes either implicitly (using the animate declaration) or explicitly (by wrapping a withAnimation function call around code that might cause changes, most notably Intent functions in the ViewModel) and can control the duration and “curve” of the animation. The “arrival and departure” of Views on screen can also be animated using the transition declaration (which declares which ViewModifiers to use to draw Views before/after they arrive/depart from the screen). In Memorize, the Cardify ViewModifier and the Pie Shape are both made Animatable and animation is applied throughout.


Leave a Comment

We don't require your email address, or your name, for anyone to leave a comment. If you do add an email address, you may be notified if there are replies to your comment - we won't use it for any other purpose. Please make respectful comments, which add value, and avoid personal attacks on others. Links are not allowed in comments - 99% of spam comments, attempt to post links. Please describe where people may find additional information - for example "visit the UN website" or "search Google for..." rather than posting a link. Comments failing to adhere to these guidelines will not be published.