Spring-Based Animations Using Damped Harmonics

Erica Sadun wrote a good introduction to adding bounce to UIViews based on spring-based animators in iOS 7:

Although you can always roll your physics-based animations, UIKit now offers one exceedingly handy built-in utility based on damped harmonics.

I’m intrigued, but memory no longer serves me (if it was ever in there at all) on damped harmonics. Google turned up this:

Damped Harmonic Oscillators on iOS 71

On second thought, let’s skip the refresher and look at the API. There is one method needed to create a range of effects:


Erica continues:

Instead of just animating a view linearly to some point on the screen, this new spring-based animation enlivens the transition. The call enables a view to bounce a little (or a lot) as it approaches its targeted position. Based on a damped harmonic spring, you specify the animation’s duration, a damping constant, and an initial view velocity as the view begins participating.

The video below shows an example of a spring-based animation: