CAKeyframe动画和音频同步
我正在使用 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;
I am using CAKeyframeAnimation to perform few animations in my app. I would like to play an audio file (sometimes during and sometimes after) along with the animations. How can I achieve this? Is there a AnimationDidStopSelector for CAKeyframeAnimation or is there another approach for doing this?
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其实是有的。首先将自己指定为委托:
如果您想使用不同的动画,可以使用 KVC 来区分它们:
然后实现此方法
Actually there is. First assign yourself as delegate:
If you want to use different animations you can use KVC to differentiate between them:
Then implement this method