Graphics Reference
In-Depth Information
LISTING 4-7
Continued
NSMutableArray *values = [ NSMutableArray array];
// Turn right
[values addObject :DegreesToNumber(-2)];
// Turn left
[values addObject :DegreesToNumber(2)];
// Turn right
[values addObject :DegreesToNumber(-2)];
// Set the values for the animation
[animation setValues :values];
return animation;
}
LISTING 4-8
Utility Functions for Converting Degrees to Radians
NSNumber* DegreesToNumber( CGFloat degrees)
{
return [ NSNumber numberWithFloat :
DegreesToRadians(degrees)];
}
CGFloat DegreesToRadians( CGFloat degrees)
{
return degrees * M_PI / 180;
}
The first keyframe in Listing 4-7 turns the icon two degrees to the right, the second turns
it two degrees to the left, and the third turns it two degrees to the right again. When the
animation has completed, it starts over again and runs 10,000 times as indicated by our
call to -setRepeatCount:10000 . This gives the visual impression of the image shaking
on a center axis. To stop the animation, remove it from the layer with a call to
-removeAnimationForKey:@”rotate” .
 
Search WWH ::




Custom Search