2010-06-04 194 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