2010-01-04 14 views
6

Attualmente ho questo codice che funziona benecacao setAnimationDidStopSelector

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

- (void)animationDone:(NSString *)animationID finished:(BOOL)finished context:(void *)context { 
// do stuff here 
} 

Registrazione del valore di animationID mi dà un nullo.

Come posso passare il valore a @selector?

ho cercato

[UIView setAnimationDidStopSelector:@selector(animationDone:@"animation1"finished:context:)]; 

Questo mi dà un errore.

Grazie, Tee

risposta

16

La stringa passata al selettore è quello utilizzato in questa chiamata di metodo:

[UIView beginAnimations:@"your_animation_name_here" context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 
// whatever changes here 
[UIView commitAnimations]; 

In seguito, si può fare questo:

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context 
{ 
    if ([animationID isEqualToString:@"your_animation_name_here"]) 
    { 
     // something done after the animation 
    } 
} 
+1

questo: '[UIView setAnimationDidStopSelector: @selector (animationDone: finished: context :)];' dovrebbe essere questo: '[UIView setAnimationDidStopSelector: @selector (animationFinished: finished: contex t :)]; ' –

+0

Grazie per il commento! Corretto. –