Graphics Reference
In-Depth Information
LISTING 4-10
Continued
// Start drawing the path
CGContextBeginPath (context);
CGContextAddPath (context, path);
// Set the line width to 3 pixels
CGContextSetLineWidth (context, 3.0);
// Draw the path
CGContextStrokePath (context);
// Release the path
CGPathRelease (path);
}
}
Starting and Stopping the Animation
Core Animation doesn't directly provide start and stop methods. However, the animation
starts when you add an animation to a layer, and the animation stops when you remove
an animation from a layer. To determine if an animation is currently running, query the
animation's dictionary to determine if the animation is still there. If it is, the animation is
still running. If it is not, the animation has stopped.
Listing 4-11 demonstrates how you start and stop the shake animation. When the anima-
tion starts, add the close box layer first and then add the animation for key rotate . This
key is important because it is used to refer to the animation when you want to stop it and
to see if it is still running.
LISTING 4-11
Controlling Animation Start and Stop
- ( void )toggleShake;
{
if ( [ self isRunning] )
{
[ self stopShake];
}
else
{
[ self startShake];
}
}
- ( BOOL )isRunning;
{
return ([ self animationForKey : @”rotate” ] != nil );
 
Search WWH ::




Custom Search