2010-06-09 2 views
0

안녕하세요 두 개의 CALayers (* layer1 및 * layer2)가 있습니다. 내가 원하는 것은 레이어 1의 애니메이션 시간의 50 %가 경과했을 때 레이어 2에서 애니메이션을 시작하는 것입니다. 어떻게하면 될까요?여러 CALayers에서 애니메이션 시간을 조정하는 방법은 무엇입니까?

CAAnimationGroup을 사용해 보았지만 동일한 레이어의 애니메이션에서만 작동합니다. 지연된 애니메이션을 먼저 그룹에 추가하고 beginTime 속성을 설정해야하는 해결 방법을 찾았습니다. 그러나 이것은 나에게 조금 해킹 된 것처럼 보입니다. 원하는 것을 성취 할 올바른 방법이 있는지 알고 싶습니다.

감사합니다.

답변

0

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