Graphics Reference
In-Depth Information
.
Ease in, where your animation starts out slowly and then reaches full speed.
.
Ease out, where your animation starts out at full speed and then slows as it reaches
its destination value.
.
Ease in, ease out, where your animation starts out slow, speeds up in the middle,
and then slows down again as it reaches its destination value; this is the default
behavior.
All the calculations are done for you automatically, you simply specify which pacing func-
tion you want to use. If you decide, however, that you want to have more control over
the pacing of your animation, you can specify an array of timing functions and times in
a keyframe animation that will give you the control you are looking for. You learn more
about animation pacing in Chapter 4.
Math? I Was Told There Would Be No Math
When you first start using Core Animation, you might assume you need to use trigono-
metric equations to do complex calculations for effects such as scaling and rotation.
Fortunately, this is not the case. The scale and rotation, and a slew of other properties, are
animatable with little code. You simply specify start and stop values along with the prop-
erty you want to animate, and Core Animation handles the rest.
In one of our earliest blog posts 2 on Core Animation, we explain how to scale a cluster of
layers. We referred to the effect as the Dashboard Effect. We later realized that when
people think of an effect in Dashboard, they are usually thinking of the ripple effect you
see when you add a new widget to the Dashboard. What we mean by Dashboard Effect,
however, is the effect you see when you initiate the Dashboard with a key-press or a hot
corner, depending on how you have it configured in the Mac OS. The widgets appear to
fade and fly in from outside of your screen when you open Dashboard. And when you
close it, they fade and fly out.
At first, we tried to figure out the equations for scaling each layer manually, but then it
became clear that Core Animation layers use a tree hierarchy and automatically cascade
effects to child layers. What this means in essence is that all you need to do is add the
cluster of layers to one large parent layer and simply scale that parent layer, and all the
child layers will automatically scale with it. You can achieve this effect with the code in
Listing 1-1.
LISTING 1-1
Scaling Layers
- ( void )doItIn:( float )duration
{
// Set the animation duration
[[NSAnimationContext currentContext] setDuration:duration];
2 Core Animation Tutorial: Dashboard Effect http://www.cimgf.com/2008/03/15/core-animation-
tutorial-dashboard-effect/.
 
 
Search WWH ::




Custom Search