本文介绍了带有延迟的Poptorootviewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个执行poptorootviewcontroller的方法 test。我想在poptorootviewcontroller的动画之前添加一些延迟。这是我的代码:
I have a method "test" that execute poptorootviewcontroller. I want to put some delay before the animation of poptorootviewcontroller. Here is my code :
-(void)test{
[UIView animateWithDuration:5.0
delay: 2.5
options: UIViewAnimationOptionCurveEaseIn
animations:^{
[self.navigationController popToRootViewControllerAnimated:NO];
}
completion:nil];
}
但这是行不通的。
有什么帮助吗?谢谢!
But it doesn't work.Any help? Thanks!
推荐答案
您发布的代码用于执行动画,而不是延迟。
The code you posted is for performing an animation, not delaying.
一个好的解决方案是使用 dispatch_after
:
A good solution would be to use dispatch_after
:
-(void)test{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popToRootViewControllerAnimated:NO];
});
以任意延迟替换 2.5
这篇关于带有延迟的Poptorootviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!