Graphics Reference
In-Depth Information
LISTING 4-11
Continued
}
- ( void )startShake;
{
[ self addSublayer :closeLayer];
// Tell the closeLayer to draw its contents which is
// an 'X' to indicate a close box.
[closeLayer setNeedsDisplay ];
[ self addAnimation :[ self shakeAnimation] forKey : @”rotate” ];
}
- ( void )stopShake;
{
[closeLayer removeFromSuperlayer ];
[ self removeAnimationForKey : @”rotate” ];
}
When -stopShake is called, the close box layer is first removed from its parent layer and
then we remove the animation from the layer. To determine whether the animation is still
running, -isRunning checks to see if the animation is still in the animations dictionary. If
it is there, the animation is running, otherwise, it is not.
NOTE
Icon Dance Animation for iPhone
Two version of this example application are available: one for OS X and one for the iPhone.
Notice some differences between them in implementation. Here are the things you need to
watch for:
.
Colors: On OS X, use CGColorCreateGenericRBG . On the iPhone, use [[UIColor
colorName] CGColor] .
.
Positions: When the position of a layer or its frame is set, the two coordinate
systems are opposite by default. This means that the close box and the image are
both drawn at the bottom of the frame instead of the top on the iPhone version if you
used the same code. The easiest way to make them match is to set the OS X view to
override the -isFlipped method and return YES , and then use the iPhone version of
the code. Then they will both use the same coordinate system. In the sample code,
however, we just changed the positions so you can see the differences.
.
CATextLayer: At the time of this writing, CATextLayer is not available on the iPhone,
so we stripped that out of the ImageLayer class on the iPhone version.
 
Search WWH ::




Custom Search