2010-01-04 16 views
6

Hiện nay tôi có mã này hoạt động tốtCocoa setAnimationDidStopSelector

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

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

Logging giá trị của animationID mang lại cho tôi một null.

Làm cách nào để chuyển giá trị cho @selector?

tôi đã cố gắng

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

Đó mang lại cho tôi một lỗi.

Cảm ơn, Tee

Trả lời

16

Chuỗi truyền cho bộ chọn là một trong những bạn sử dụng trong cuộc gọi phương pháp này:

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

Sau đó, bạn có thể làm điều này:

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

này: '[UIView setAnimationDidStopSelector: @selector (animationDone: finished: context :)];' nên là: '[UIView setAnimationDidStopSelector: @selector (animationFinished: finished: contex t :)]; ' –

+0

Cảm ơn bạn đã bình luận! Đã sửa. –