UINavigationController自定义动画阻止滑动后退功能 [英] UINavigationController custom animation prevents swipe-to-go-back from working
问题描述
我注意到一些奇怪的事情,可能是UINavigationController中的错误.当您覆盖
-navigationController:animationControllerForOperation:fromViewController:toViewController:
I noticed something strange and may possibly be a bug in UINavigationController. When you override
-navigationController:animationControllerForOperation:fromViewController:toViewController:
并返回nil(用于默认动画行为),则后退拖动手势将不再起作用.此方法的文档说,您应该返回"nil,如果要使用标准导航控制器转换".我的理解是,返回nil不应阻止默认行为的发生.
and return nil (for the default animation behavior), the drag-to-go-back gesture no longer works. The documentation for this method says you should return " nil if you want to use the standard navigation controller transitions". My reading of this is that returning nil should not prevent the default behavior from happening.
我还发现,如果导航控制器的InteractivePopGestureRecognizer.delegate带有对gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
返回YES的内容
弹出手势再次起作用.但是,由于我们要踩踏已安装的默认委托_UINavigationInteractiveTransition,因此此解决方法存在风险.
I also found that if the navigation controllers's interactivePopGestureRecognizer.delegate with something that returns YES for gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
The pop gesture works again. However, this workaround is risky since we are stomping on the default delegate that is installed, which is a _UINavigationInteractiveTransition.
在保留默认的拖后移动手势的同时,是否有办法可以覆盖animationController方法?
Is there someway I can override the animationController method while retaining the default drag-to-go-back gesture?
此问题是相关的.
推荐答案
如果您将UINavigationController子类化,则最简单的修复方法如下(iOS 9.3,Swift 2.2):
If you've subclassed UINavigationController, the simplest fix is as follows (iOS 9.3, Swift 2.2):
override func viewDidLoad() {
super.viewDidLoad()
interactivePopGestureRecognizer?.delegate = nil
}
或者,在UIViewController的任何其他实例中:
Alternatively, in any other instance of UIViewController:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.interactivePopGestureRecognizer?.delegate = nil
}
实施委托方法navigationController(_:animationControllerFor:from:to:)
会禁用导航控制器的交互式弹出手势识别器,但是将手势的委托设置为nil会重新启用它.
Implementing the delegate method navigationController(_:animationControllerFor:from:to:)
disables the navigation controller's interactive pop gesture recognizer, but setting the gesture's delegate to nil re-enables it.
如果仅希望在特定情况下启用手势,请参见此答案.
If you only want the gesture to be enabled in particular circumstances, see this answer.
这篇关于UINavigationController自定义动画阻止滑动后退功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!