1

我正在使用 CAKeyframeAnimation 在我的应用程序中执行一些动画。我想与动画一起播放音频文件(有时在期间,有时在之后)。我怎样才能做到这一点?是否有 CAKeyframeAnimation 的 AnimationDidStopSelector 或者有其他方法可以做到这一点?

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;
4

1 回答 1

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
    }
}
于 2011-09-26T16:04:55.183 回答