Poptorootviewcontroller with delay

这一生的挚爱 提交于 2019-12-12 04:53:12

问题


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!


回答1:


The code you posted is for performing an animation, not delaying.

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];
    });

Replace the 2.5 with whatever delay you want.



来源:https://stackoverflow.com/questions/26978577/poptorootviewcontroller-with-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!