2012-05-03 67 views
2

我正在处理一个简单的UIImageView动画。基本上我从0-9中得到了一堆图像数字,并且我正在使用此代码对它们进行动画处理。检查动画停止时

myAnimation.animationImages = myArray; 
myAnimation.animationDuration = 0.7; 
myAnimation.animationRepeatCount = 12; 
[myAnimation startAnimating]; 

这里myArray的是uiimages即0.png,1.png等

阵列一切都很好,它的动画就好了。我需要知道的是什么时候知道动画何时停止?我可以使用NSTimer,但为此我需要一个秒表来检查动画何时开始和停止。有没有更好的方法,这意味着有什么方法可以找出UIImageView何时停止动画?

我看着这个线程作为参考。

UIImageView startAnimating: How do you get it to stop on the last image in the series?

+0

看来,你正在做一个UIImageView动画不是一个UIView动画如你所述。所以你得到了你想要的错误答案。你应该解决这个问题。 – Joel

+0

正确对不起我的问题中的错字。是的,我正在动画UIImageView而不是UIView。任何人都可以纠正我的文章中的编辑 - 将UIView更改为UIImageView。我无法再编辑这个问题了。谢谢 –

回答

4

使用animationDidStopSelector。这将火的时候,动画完成:

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

然后实现选择:

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

} 
+0

en ....还应该加上[UIView setAnimationDelegate:self]我经常忘记,哈〜 – Tranz

+0

嗨Joel,谢谢你的回答,但是我怎么知道它需要检查哪个UIImageview来查看它是否停止了动画?我希望我可以修改上面的问题,并将UIView更改为UIImageView。 –

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或安排的活动

+0

对不起,我在我的问题上有一个错字。我想问如何检查UIImageView何时停止动画。 –

0

你也可以试试这个:

[self performSelector:@selector(animationDone) withObject:nil afterDelay:2.0];