2011-09-26 4 views
1

CAKeyframeAnimation을 사용하여 앱에서 거의 애니메이션을 수행하지 않습니다. 나는 애니메이션과 함께 (때로는 그리고 때로는) 오디오 파일을 재생하고 싶다. 이것을 어떻게 할 수 있습니까? CAKeyframeAnimation 용 AnimationDidStopSelector가 있습니까? 아니면이 작업을 수행하는 다른 방법이 있습니까?CAKeyframeAnimation 및 오디오 동기화

UIBezierPath *movePath = [UIBezierPath bezierPath]; 
      [movePath moveToPoint:imageAnimation.center]; 
      [movePath addQuadCurveToPoint:CGPointMake(839, 339) 
          controlPoint:CGPointMake(671, 316)]; 

      CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
      moveAnim.path = movePath.CGPath; 
      CAAnimationGroup *animGroup = [CAAnimationGroup animation]; 
      animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil]; 
      animGroup.duration = 0.5; 
      imageAnimation.layer.position = CGPointMake(839, 339); 
      imageAnimation.tag = 0; 
      [imageAnimation.layer addAnimation:animGroup forKey:nil]; 
      break; 

답변

0

실제로 있습니다. 첫째 대리인으로 자신을 할당합니다

animGroup.delegate = self 

을 당신이 당신이 그들을 구분하는 KVC를 사용할 수있는 다양한 애니메이션을 사용하려면 :

[yourAnimation setValue:@"firstAnimation" forKey:@"animationName"]; 

그런 다음이 방법

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag 
{ 
    if (flag && [[anim valueForKey:@"animationName"] isEqualToString:@"firstAnimation"]) { 
     //play your sound 
    } 
    else if (flag && [[anim valueForKey:@"animationName"] isEqualToString:@"secondAnimation"]) { 
     //do something else 
    } 
} 
+0

감사 바르 토스를 구현합니다. '[imageAnimation.layer addAnimation : animGroup forKey : nil] 다음에 animationDidStop : 메소드를 명시 적으로 호출해야합니까? '? – Alex

+0

아니요, 애니메이션이 중지되면 자동으로 호출됩니다. –

+0

CA 그룹 애니메이션이 여러 개있는 경우 animationDidStop : 메소드 내에 어떻게 조건문을 사용할 수 있습니까? – Alex