UINavigationController交互式stream行手势不工作?

所以我有一个导航控制器在我的iOS 7应用程序的内置。 titleView是可见的,以及后退button和导航栏的自我。 出于某种原因,交互式popup手势(从左边缘滑动)不起作用。 什么都没发生。 当我login手势时,不是零。 有什么特别的我必须做,以启用此function? 什么可能导致它不工作?

呃,看起来我只需要设置姿态委托,并执行以下操作:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

看看这个回复和评论。 您只需将导航控制器的交互式popup手势识别器的代理设置nil

 self.navigationController.interactivePopGestureRecognizer.delegate = nil; 

把它设置为id<UIGestureRecognizerDelegate>也是id<UIGestureRecognizerDelegate>因为协议中的所有方法都是可选的,但是我认为在这种情况下将nil设置为nil更合适。

我发现在使用自定义后退button时,交互式popup手势停止工作(我认为苹果公司无法预见自定义后退button的行为方式,因此它们会禁用该手势)。

要解决这个问题,就像之前提到的那样,可以将interactivePopGestureRecognizer.delegate属性设置为nil

在Swift中, 这可以通过像这样为UINavigationController添加一个扩展来轻松地在整个应用程序中完成

 extension UINavigationController { override public func viewDidLoad() { super.viewDidLoad() interactivePopGestureRecognizer?.delegate = nil } } 

更新了答案

似乎将代理设置nil会导致应用程序UI在某些情况下(例如,用户在导航堆栈的顶部视图控制器上左右滑动)冻结。

由于gestureRecognizerShouldBegin委托方法不能在扩展中处理, UINavigationController子类似乎是最好的解决scheme:

 class NavigationController: UINavigationController, UIGestureRecognizerDelegate { /// Custom back buttons disable the interactive pop animation /// To enable it back we set the recognizer to `self` override func viewDidLoad() { super.viewDidLoad() interactivePopGestureRecognizer?.delegate = self } func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { return viewControllers.count > 1 } } 

你可以把这一行放在viewDidLoad方法中。

 self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self; 

Aaron和Lojals都是更有效的答案

首先自定义导航控制器,然后把这个代码放在类中

在ViewDidload中放置这一行:

 self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self; 

并在课堂上写这个function

 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES;}