2012-01-05 70 views
6

在我的iPhone應用程序中動畫完成後想要調用一些方法

我在做某些動畫。 像

[UIView beginAnimations:@"stalk" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.frame=originalSelf; 
    [UIView commitAnimations]; 

這個動畫我想tocall一些方法完成後...

我知道的東西ABT塊動畫或

DidStopAnimation通知

我怎麼做.. .. 謝謝..

回答

11

在iOS 4及更高版本,建議爲此目的使用塊:

[UIView animateWithDuration:1 
        animations:^{ 
         self.frame=originalSelf;} 
        completion:^(BOOL finished){ 

         //My method call; 
        } 
    ]; 
5

嘗試使用

[UIView beginAnimations:@"stalk" context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(afterAnimationStops)] 
self.frame=originalSelf; 
[UIView commitAnimations]; 

然後你就可以實現方法

-(void)afterAnimationStops{ 

}