2010-06-04 143 views
0

我不想在退出視圖之前執行動畫。問題是,如果我寫這樣的代碼:執行構造前等待

[self animationMethod]; 
[self removeFromSuperview]; 

動畫沒有提出,因爲removeFromSuperview指令立刻執行,我想。

有一種方法可以指定removeFromSuperview方法必須在指定的時間之後執行嗎?謝謝。

回答

0

是否animationMethod使用[UIView beginAnimations:context:]節?如果是這種情況,你應該使用動畫委託。具體做法是:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)]; 
//Your animation stuff 
[UIView commitAnimations]; 

否則,如果你正在做別的,沒有回調,則可以使用呼叫延遲後的方法:

[self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.25f]; 

其中0.25F是延遲你想用。我選擇了0.25,因爲這是動畫塊的默認動畫長度(如上所示)。

+0

我ve arredi triade與setAnimationDidStopSelector,但沒有奏效。我遵循調試器,並將指定爲參數的metodo作爲參數d。 – Luca 2010-06-04 16:14:25

+0

現在所有作品.....隨着setAnimationDelegate:自我似乎都工作得很好!非常感謝!! – Luca 2010-06-04 16:31:54