2010-02-18 152 views
2

说我有...如何知道Core Animation何时完成?

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 

CGPoint position = myObject.center; 
position.x = position.x - 10; 

myObject.center = position; 

[UIView commitAnimations]; 

核心动画发生在一个单独的线程有没有办法知道什么时候 动画已经完成?也许有一些方法可以连接 函数调用以了解它何时完成...?

(P.S我知道我可以使用,在这个 例如上面说0.5秒后触发的方法的计时器,但似乎很俗气)

任何帮助,非常感谢!

回答

5

您可以设置setAnimationDidStopSelector:

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/setAnimationDidStopSelector

  • (无效)setAnimationDidStopSelector:(SEL)选择

然后实现方法为选择

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


- (void) finishedAnimation:(NSString *)id finished:(BOOL) finished context:(void *) context { 
    ...... 
} 

希望有所帮助秒。