2010-01-04 15 views
6

目前我有這樣的代碼工作正常可可setAnimationDidStopSelector

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

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

記錄animationID的價值給了我一個空。

如何將值傳遞給@selector?

我試圖

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

這給了我一個錯誤。

感謝, 三通

回答

16

傳遞到選擇的字符串是你在調用此方法使用一個:

[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]; 

之後,你可以這樣做:

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

這樣的: '[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context :)];' 應該是這樣的:'[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:contex t :)];' – 2010-09-13 10:01:43

+0

感謝您的評論!糾正。 – 2010-09-13 18:48:47