我正在使用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;发布于 2011-09-27 00:04:55
实际上是有的。首先将您自己指定为代理:
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
}
}https://stackoverflow.com/questions/7556955
复制相似问题