將第二個動畫添加到組的方法確實感覺像是一種黑客攻擊,但它的工作原理並且完全可以接受。但是,如果您願意,可以執行以下操作:-performSelector:withObject:afterDelay。類似這樣的:
- (void)startFirstAnimation;
{
CGFloat duration = 10.0;
CABasicAnimation *firstAnim =
[CABasicAnimation animationWithKeyPath:@"position"];
[firstAnim setFromValue:
[NSValue valueWithCGPoint:CGPointMake(30.0f, 30.0f)]];
[firstAnim setToValue:
[NSValue valueWithCGPoint:CGPointMake(200.0f, 200.0f)]];
[firstAnim setDuration:duration];
[firstLayer addAnimation:firstAnim forKey:nil];
[self performSelector:@selector(startSecondAnimation)
withObject:nil afterDelay:duration/2.0];
}
- (void)startSecondAnimation;
{
CABasicAnimation *secondAnim =
[CABasicAnimation animationWithKeyPath:@"position"];
[secondAnim setFromValue:
[NSValue valueWithCGPoint:CGPointMake(100.0f, 30.0f)]];
[secondAnim setToValue:
[NSValue valueWithCGPoint:CGPointMake(200.0f, 200.0f)]];
[secondAnim setDuration:5.0];
[secondLayer addAnimation:secondAnim forKey:nil];
}