我正在制作一个简单的UIImageView动画。基本上,我得到了一堆从0到9的图像数字,我使用下面的代码对它们进行动画处理。
myAnimation.animationImages = myArray;
myAnimation.animationDuration = 0.7;
myAnimation.animationRepeatCount = 12;
[myAnimation startAnimating];这里的myArray是uiimage的数组,例如0.png,1.png等。
一切都很好,它的动画也很好。我需要知道的是,我什么时候知道动画何时停止?我可以使用NSTimer,但我需要一个秒表来检查动画何时开始和停止。有没有更好的方法,也就是说,有没有办法让我知道UIImageView何时停止了动画?
我把这个帖子当做参考。
UIImageView startAnimating: How do you get it to stop on the last image in the series?
发布于 2012-05-03 23:52:28
使用animationDidStopSelector。这将在动画完成时触发:
[UIView setAnimationDidStopSelector:@selector(someMethod:finished:context:)];然后实现选择器:
- (void)someMethod:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {
}发布于 2012-05-03 23:52:47
是的,有一种比使用NSTimers更好的方法。如果你使用的是iOS 4或更高版本,最好开始使用块动画。尝尝这个
[UIView animateWithDuration:(your duration) delay:(your delay) options:UIViewAnimationCurveEaseInOut animations:^{
// here you write the animations you want
} completion:^(BOOL finished) {
//anything that should happen after the animations are over
}];编辑:哦,我想我把你的问题看错了。对于UIImageView动画,我想不出比使用NSTimers或计划事件更好的方法了
发布于 2012-05-03 23:54:43
您还可以尝试执行以下操作:
[self performSelector:@selector(animationDone) withObject:nil afterDelay:2.0];https://stackoverflow.com/questions/10434849
复制相似问题