如果视图控制器转换过快,应用程序崩溃 [英] App crashes if view controller transition is done too quickly

查看:940
本文介绍了如果视图控制器转换过快,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用视图控制器包含来在6个视图控制器之间进行转换。使用分段控制来控制转换。除非在前一个转换的动画完成之前按下分段控件上的按钮,否则一切正常。在这种情况下,应用程序崩溃

I am using view controller containment to transition between 6 view controllers. Transitions are controlled using a segmented control. This all works fine unless buttons on the segmented control are pushed before animation of the previous transition has completed. In this situation, the app crashes with

'子视图控制器,并且在调用时必须有一个公共父视图控制器 - [UIViewController transitionFromViewController:toViewController:duration:options:animations:完成:]'

'Children view controllers and must have a common parent view controller when calling -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'

代码是:

[self transitionFromViewController:currentVC
                  toViewController:newVC
                          duration:1.0
                           options:UIViewAnimationOptionTransitionFlipFromRight
                        animations:nil
                        completion:^(BOOL finished) {
                            [currentVC removeFromParentViewController];
                            [newVC didMoveToParentViewController:self];
                            currentVC = newVC;
                        }];

我应该在动画完成之前禁用分段控件吗?或者他们是避免这个问题的更好方法吗?

Should I disable the segmented control until animation is completed? Or is their a better way to avoid this issue?

推荐答案

您可以通过调用

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];

。然后应用程序将忽略所有交互(触摸事件),直到动画结束,因此该段在安全之前永远不会接收事件(动画完成)。

when the animation starts and ends respectively. The app will then ignore all interaction (touch events) until the animation is finished, so the segment will never receive event before it is safe (animations are done).

I认为这种方法也适用于某些内置容器控制器。但请注意动画持续时间。如果动画需要很长时间,看起来应用程序响应不好,这会伤害用户体验

I think this approach is used on some built-in container controllers as well. However be careful about animation duration. If the animation will take a long time, it can look like the app is not responding well, which hurts user experience

这篇关于如果视图控制器转换过快,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆