Graphics Reference
In-Depth Information
.
Core Graphics paths are used for moving objects from point-to-point around the
screen on a path. Whenever a CGPoint is the type of the property, a Core Graphics
path is likely the right choice. You will use the anchorPoint and position properties
to animate paths.
In terms of precedence, a path overrides an array of values. This means that if you specify
a path with a call to -setPath , anything specified in the values field with a call to
-setValues will be ignored. The code in Listing 4-1 and Listing 4-2 demonstrates how to
use a Core Graphics path and an array of values, respectively. The listings are functionally
the same, yet the result is quite different. The animation in Listing 4-1 causes the layer to
bounce across the screen in an arcing parabolic pattern. Listing 4-2 causes the layer to
bounce across the screen in more of a square tooth pattern.
LISTING 4-1
Path Animation
- ( CAAnimation *)pathAnimation;
{
CGMutablePathRef path = CGPathCreateMutable ();
CGPathMoveToPoint (path, NULL ,50.0,120.0);
CGPathAddCurveToPoint (path, NULL ,50.0,275.0,150.0,275.0,150.0,120.0);
CGPathAddCurveToPoint (path, NULL ,150.0,275.0,250.0,275.0,250.0,120.0);
CGPathAddCurveToPoint (path, NULL ,250.0,275.0,350.0,275.0,350.0,120.0);
CGPathAddCurveToPoint (path, NULL ,350.0,275.0,450.0,275.0,450.0,120.0);
CAKeyframeAnimation *
animation = [ CAKeyframeAnimation
animationWithKeyPath : @”position” ];
[animation setPath :path];
[animation setDuration :3.0];
[animation setAutoreverses : YES ];
CFRelease (path);
return animation;
}
 
Search WWH ::




Custom Search