두 번째 애니메이션을 그룹에 추가하는 방법은 약간의 해킹처럼 느껴지지만 제대로 작동합니다. 그래도 원하는 경우 할 수있는 일은 -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];
}