Graphics Reference
In-Depth Information
11
Timer-Based Animation
I can guide you, but you must do exactly as I say.
Morpheus, The Matrix
In Chapter 10, “Easing,” we looked at CAMediaTimingFunction , which enables us to
control the easing of animations to add realism by simulating physical effects such as
acceleration and deceleration. But what if we want to simulate even more realistic physical
interactions or to modify our animation on-the-fly in response to user input? In this chapter,
we explore timer-based animations that allow us to precisely control how our animation
will behave on a frame-by-frame basis.
Frame Timing
Animation appears to show continuous movement, but in reality that's impossible when the
display pixels are at fixed locations. Ordinary displays cannot display continuous
movement; all they can do is display a sequence of static images fast enough that you
perceive it as motion.
We mentioned previously that iOS refreshes the screen 60 times per second. What
CAAnimation does is calculate a new frame to display and then draws it in sync with each
screen update. Most of the cleverness of CAAnimation is in doing the interpolation and
easing calculations to work out what to display each time.
In Chapter 10, we worked out how to do the interpolation and easing ourselves, and then
essentially told a CAKeyframeAnimation instance exactly what to draw by providing an
array of frames to be displayed. All Core Animation was doing for us at that point was
displaying those frames in sequence. Surely we can do that part ourselves as well?
 
 
Search WWH ::




Custom Search