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.
精彩评论