Graphics Reference
In-Depth Information
LISTING 3-13
Continued
[boundsAnimation setFromValue :[ NSValue valueWithRect:oldRect]];
[boundsAnimation setToValue:[ NSValue valueWithRect:newRect]];
[boundsAnimation setDuration :15.0f];
[boundsAnimation setBeginTime :0.0f];
CABasicAnimation *positionAnimation =
[ CABasicAnimation animationWithKeyPath : @”position” ];
[positionAnimation setFromValue :
[ NSValue valueWithPoint:
NSPointFromCGPoint([layer position ])]];
[positionAnimation setToValue:
[ NSValue valueWithPoint:NSMakePoint(0.0, 0.0)]];
[positionAnimation setDuration :15.0f];
[positionAnimation setBeginTime :5.0f];
CABasicAnimation *borderWidthAnimation =
[ CABasicAnimation animationWithKeyPath : @”borderWidth” ];
[borderWidthAnimation setFromValue :[ NSNumber numberWithFloat :5.0f]];
[borderWidthAnimation setToValue:[ NSNumber numberWithFloat :30.0f]];
[borderWidthAnimation setDuration :15.0f];
[borderWidthAnimation setBeginTime :10.0f];
CAAnimationGroup *group = [ CAAnimationGroup animation ];
[group setDuration :15];
[group setAnimations :
[ NSArray arrayWithObjects :boundsAnimation,
positionAnimation,
borderWidthAnimation, nil ]];
[layer addAnimation :group forKey : nil ];
}
Notice that we have set the duration for each of the individual animations to the full
fifteen seconds, but each of the animations have their begin times set to start one after
the other at 0.0 , 5.0 , and 10.0 .
You also notice that the only thing we add to the layer is the group animation. The
animation objects in the group have been added with a call to -setAnimations .
You can see that there is a good bit of flexibility provided through grouping. You just
need to tweak your durations and begin times to suit your needs. If you want the anima-
tions to overlap, you just change the begin times to reflect when you want them to start
playing back. You want to keep your duration times all the same; otherwise each keypath
value (that is, bounds , position , and borderWidth ) in the layer snaps back to its original
 
Search WWH ::




Custom Search