views:

107

answers:

1

say I have...

[UIView beginAnimations: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!

+3  A: 

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.

Tone