如何取消PresentViewController动画

时间:2014-11-22 15:28:13

标签: ios uiviewcontroller presentviewcontroller poptoviewcontroller

我有viewController1(在UINavigationController中),它呈现了viewController2 问题在于,当呈现viewController2时(大约需要0.2秒),应用程序中的事件可能会导致viewController1被弹出。

然后我得到:

DetailsViewController的开始/结束外观转换的非平衡调用:0x7e6191a0。

并且viewController2在屏幕上保持“孤立”状态(无法将其删除)..

这是代码(在Xamarin c#中,但它与Objective C中的问题相同):

this.PresentViewController(viewController2, animated: true, completionHandler: null); // takes 0.2s to animate
//
// then 0.1s later, say, this is called:
//
this.DismissViewController(animated: false, completionHandler: null);
this.NavigationController.PopToRootViewController(animated: false);

问题是this.DismissViewController实际上并没有在它仍然是动画时解除它。

(如果正在进行推送动画,则会出现类似问题。)

解决方案是“排队”PopToRootViewController的请求,并在this.PresentViewController的completionHandler中运行它。 但这非常麻烦,意味着应用程序中的所有事件都必须排队,并且所有动画都必须有completionHandler的。

我真的需要一种取消当前动画的方法(this.View.Layer.RemoveAllAnimations()不适用于presentViewController),这样DismissViewController就可以正常工作,并且可以毫无问题地调用PopToRootViewController。

人们如何处理这种“无法解决的动画”问题?

更新:

还有一个相关的问题,现在我们必须使用UIAlertController而不是UIAlert,参见背景:

Show UIAlertController if already showing an Alert

在呈现UIAlertController之前,我们必须等待任何presentViewController动画完成。这对于我们希望在警报中显示的推送通知这样的事情很难,但它可能会在动画期间到达。

0 个答案:

没有答案