我如何等到不同类中的动画完成后再继续?
我有简单的代码:
[otherClass doMethodOneWhichHasAnimation];
动画持续 0.8 秒。接下来是推送视图控制器的代码:
SchemeView *schemeView = [[SchemeView alloc] init];
[self.navigationController pushViewController:schemeView animated:YES];
[schemeView release];
问题是,它不等待就推送视图控制器,而我希望它等待。延迟只会延迟整个过程,包括第一个动画的开始。
我怎样才能让它在运行第二段代码之前等待 0.8 秒?
I have the simple code of:
[otherClass doMethodOneWhichHasAnimation];
and that animation lasts 0.8 seconds. Followed by code that pushes a viewcontroller:
SchemeView *schemeView = [[SchemeView alloc] init];
[self.navigationController pushViewController:schemeView animated:YES];
[schemeView release];
The problem is, it pushes the viewcontroller without waiting, and I'd like it to wait. Doing delay just delays the whole thing, including the first animation from starting.
How can i get it to wait the 0.8 seconds before running the second bit of code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在动画完成后推送
<< iOS 4+ 看看 setAnimationDidStopSelector
或
You can push after the animation is done
for < iOS 4+ take a look at setAnimationDidStopSelector
or
您可以使用 CATransaction 在任何动画之后运行完成块,而无需更改创建动画的方法的源代码。您需要链接到
QuartzCore
框架,并且您需要#import
。然后你可以这样做:You can use
CATransaction
to run a completion block after any animation, without changing the source code of the method that creates the animation. You'll need to link with theQuartzCore
framework and you'll need to#import <QuartzCore/QuartzCore.h>
. Then you can do this:我通过创建一个新类来运行动画来解决这个问题。
此类计算与动画开始同步经过的时间。
您将动画的时间输入到类中,动画块和类计数器都会接收该数字。
当计数器到达末尾时,您知道动画也已完成。
...所有这些都没有随机复杂的库。
I got around this problem by making a new class to run animations.
This class counts how much time as passed synchronized with the start of the animation.
You feed in the time for the animation to the class and both the animation block and the class counter takes that number in.
When the counter has reached its end you know that the animation has also finished.
...All without random complicated Libraries.
只需调用具有延迟时间间隔的方法,
例如:
simply call a method with the delayed time interval
like-