开发者

Wait before execute istruction

I wan't to perform an animation before quitting a view. The problem is that if I write this code:

[self animationMethod];
[self removeFromSuperview];

the animation is not presented because the remov开发者_运维百科eFromSuperview instruction is immediatly executed, i suppose.

There's a way to specify thath the removeFromSuperview method must be executed after a a specified time? thanks.


Does animationMethod use a [UIView beginAnimations: context:] section? If that's the case, you should use the animation delegate. Specifically:

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

Otherwise, if you're doing something else that doesn't have a callback, you can call the method after a delay using:

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

where 0.25f is the delay you want to use. I chose 0.25 because that is the default animation length for animation blocks (as shown above).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜