嗨,我正在创建一个应用程序,其中有一个动画后播放一个动画,然后它变成空白,我需要一种方式来声明动画结束播放声音时,我有声音代码,所以我只需要知道如何陈述它,我正在使用代码,如[animation startanimating]
和[animation stopanimating]
,[audioplayer play]
和[audioplayer stop]
。谢谢我是初学者,所以请去容易:)如何声明动画结束?
回答
您可以转换您的代码使用一个完成回调块。 this答案中的示例。
编辑与例如:
比方说,你想动画的观点被称为myView
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
myView.alpha = 0; // a fade out animation
}
completion:^(BOOL finished)
{
[audioPlayer play];
// whatever else
}
];
这是你尝试过什么?你能发布更多的实际代码吗?它有助于了解您如何处理整个动画和回调。
嘿,正如我所说我是一个总的初学者和我试过这样做,但它不起作用,可能是因为我没有做对吗? – user1483652 2012-07-20 16:03:57
这是我完成它的方式:^(BOOL finished){audioPlayer play]; play.hidden = 0; }; – user1483652 2012-07-20 16:04:36
好吧,我会创建一个粘贴bin并把链接放在这里几分钟,它会有整个代码:) – user1483652 2012-07-20 16:22:01
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
//animation block
// perform animation here
}
completion:^(BOOL finished){
// play sound here
[audioPlayer play]
}];
我应该把这个放在我的动画代码中吗? – user1483652 2012-07-20 16:08:02
这段代码是针对动画的......所以当你想要执行动画时写下它...... – 2012-07-20 18:17:30
您打算使用CAKeyFrameAnimation
。这将允许您通过一系列具有单独帧时间的图像生成动画效果和当您到达动画结尾时会获得委托通知,这些动画将使用UIImageView
进行动画处理,但不会提供此动画。
一些示例代码让你开始(假设ARC):
// create an animation overlay view to display and animate our image frames
UIView *animationView = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:animationView];
// using 4 images for the example
NSArray *values = [NSArray arrayWithObjects:(id)[[UIImage imageNamed:@"Image1.png"] CGImage],
(id)[[UIImage imageNamed:@"Image2.png"] CGImage],
(id)[[UIImage imageNamed:@"Image3.png"] CGImage],
(id)[[UIImage imageNamed:@"Image4.png"] CGImage],
nil];
// change the times as you need
NSArray *keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.25],
[NSNumber numberWithFloat:0.50],
[NSNumber numberWithFloat:1.0],nil];
// animating the contents property of the layer
CAKeyframeAnimation *keyframe = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
keyframe.values = values;
keyframe.keyTimes = keyTimes;
keyframe.calculationMode = kCAAnimationLinear;
keyframe.duration = 1.0; // 1 second, can be whatever you want, obviously
keyframe.delegate = self;
keyframe.removedOnCompletion = NO;
keyframe.fillMode = kCAFillModeForwards;
// "user defined string" can be whatever you want and probably should be constant somewhere in
// your source. You can use this same key if you want to remove the animation
// later using -[CALayer removeAnimationForKey:] on the animationView's layer
[animationView.layer addAnimation:keyframe forKey:@"user defined string"];
然后,别的地方,实现您的委托方法:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished
{
if (finished) {
// play music
}
}
- 1. 意外的声明结束
- 2. 如何开始动画结束活动
- 3. 如何播放一次声音或直到动画结束?
- 4. 否则如果声明结束程序
- 5. 如何通过动画结束UILongPressGestureRecognizer?
- 6. 如何处理布局动画结束
- 7. UITableView,如何捕捉动画结束?
- 8. 如何获取动画结束通知
- 9. 如何在另一个动画结束时启动动画?
- 10. 如何声明'动画停止动画'的命令?
- 11. 如何在布局动画结束时触发动画
- 12. VBS错误:“声明的预期结束”
- 13. 条件满足后结束CASE声明
- 14. 结束动画事件android
- 15. UIRefreshController结束动画问题
- 16. iPhone等待动画结束
- 17. CSS3动画结束技术
- 18. CALayer动画结束回调?
- 19. jQuery的动画与如果声明
- 20. 如何判断画布动画何时结束
- 21. 如何在大型项目中查找结束声明
- 22. jQuery检测如果CSS动画结束
- 23. Html5画布动画。如何重置矩形当它结束
- 24. 动态声明本月的开始/结束日期
- 25. 如何在Android动画结束后启动开始活动
- 26. 当动画结束时,保留动画的结尾图像
- 27. 动画结束后的Javascript performe动作
- 28. 如何在Konva动画结束时采取行动?
- 29. 我如何动画添加到活动结束()
- 30. 如何知道UIImagePickerController的“iris”启动动画是否结束?
安置自己的整个代码请。 – 2012-07-20 16:20:27
http://pastebin.com/x9m9qXcb – user1483652 2012-07-20 16:33:56
你究竟想用动画来完成什么?你想每秒翻阅一张图片吗? – 2012-07-20 16:35:24