2

我正在制作一个简单的 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:如何让它停在系列中的最后一张图片上?

4

3 回答 3

4

使用动画DidStopSelector。这将在动画完成时触发:

[UIView setAnimationDidStopSelector:@selector(someMethod:finished:context:)];

然后实现选择器:

- (void)someMethod:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {

}
于 2012-05-03T15:52:28.183 回答
1

是的,有比使用 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-03T15:52:46.787 回答
0

你也可以试试这个:

[self performSelector:@selector(animationDone) withObject:nil afterDelay:2.0];
于 2012-05-03T15:54:43.070 回答