2010-05-26 66 views
1

我已經把一行代碼放入了UIAnimation塊。下一行在動畫塊之後。我希望第二行僅在第一個動畫塊的時間間隔後執行。如何僅在動畫塊的時間間隔後執行一行代碼?

例如: -

[UIView beginAnimations:@"View Flip" context:nil]; 
[UIView setAnimationDuration:0.5]; 
//First line comes here 
[self.view addSubview:subView]; 
[UIView commitAnimations]; 

然後,第二線

[subView2 removeFromSuperView]; 

我想要的第二線只有動畫動作的0.5秒的時間間隔之後執行。有沒有可能這樣做?

回答

2

您可以設置一個委託動畫,並在其方法刪除子視圖:

... 
[UIView beginAnimations:@"View Flip" context:nil]; 
[UIView setAnimationDuration:0.5]; 

[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
[UIView setAnimationDelegate:self]; 

//First line comes here 
[self.view addSubview:subView]; 
[UIView commitAnimations]; 
... 
在委託的動畫沒有停止處理程序刪除您的第二子視圖

然後:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{ 
    if ([finished boolValue]) 
     [subView2 removeFromSuperview]; 
} 
相關問題