UINavigationController自定义动画可防止滑动返回工作

jef*_*ong 9 objective-c ios

我注意到一些奇怪的东西,可能是UINavigationController中的一个错误.当你覆盖 -navigationController:animationControllerForOperation:fromViewController:toViewController:

并返回nil(对于默认动画行为),拖放回去手势不再有效.此方法的文档说明如果要使用标准导航控制器转换,则应返回"nil".我对此的解读是,返回nil不应该阻止默认行为的发生.

我还发现,如果导航控制器的interactivePopGestureRecognizer.delegate具有返回YES gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 的弹出手势,则会再次起作用.但是,这种解决方法存在风险,因为我们正在踩踏安装的默认委托,这是一个_UINavigationInteractiveTransition.

有没有我可以覆盖animationController方法,同时保留默认的拖放回去手势?

这个问题是相关的.

jam*_*esk 5

如果你已经继承了 UINavigationController,最简单的修复如下(iOS 9.3,Swift 2.2):

override func viewDidLoad() {
    super.viewDidLoad()
    interactivePopGestureRecognizer?.delegate = nil
}
Run Code Online (Sandbox Code Playgroud)

或者,在 UIViewController 的任何其他实例中:

override func viewDidLoad() {
    super.viewDidLoad()
    navigationController?.interactivePopGestureRecognizer?.delegate = nil
}
Run Code Online (Sandbox Code Playgroud)

实现委托方法navigationController(_:animationControllerFor:from:to:)会禁用导航控制器的交互式弹出手势识别器,但将手势的委托设置为 nil 会重新启用它。

如果您只想在特定情况下启用手势,请参阅此答案


yon*_*nel 1

这个SO问题是关于同一主题的,这个答案可能会解决这个问题:

/sf/answers/1464643421/