开发者

How to know when a Core Animation has finished?

say I have...

[UIView begi开发者_如何学编程nAnimations:nil context:NULL];  
[UIView setAnimationDuration:0.5];

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

myObject.center = position;

[UIView commitAnimations];

Core animation happens on a separate thread is there a way to know when an animation has finished? i.e., maybe there's some way I can hook up a function call to know when it got finished... ?

(p.s I know I can use a timer that fires a method after say 0.5s in this above example, but that seems pretty cheesy)

any help much appreciated!


You can set the setAnimationDidStopSelector:

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

  • (void)setAnimationDidStopSelector:(SEL)selector

Then implement a method for that selector

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


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

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜