隐藏导航栏时,UINavigationContoller interactivePopGestureRecognizer处于非活动状态

Dan*_*Dan 18 uinavigationbar uinavigationcontroller uigesturerecognizer ios7

我有一个嵌套在一个视图控制器UINavigationController.

我已经实现了iOS 7的interactivePopGestureRecognizer,使用户可以手势将VC从堆栈中弹出.

在VC中我有一个滚动视图,当用户不在滚动视图的顶部时,我隐藏了所有的chrome(导航栏和状态栏)以将焦点放在内容上.

但是,如果隐藏了导航栏,则interactivePopGestureRecognizer将无法正常工作.

我已经尝试在它消失后启用它并验证它不是零,但它仍然不起作用.

有什么我想念的吗?

sim*_*dox 37

将您的UIViewController子类设置为gestureRecognizer的委托:

self.navigationController.interactivePopGestureRecognizer.delegate = self;
Run Code Online (Sandbox Code Playgroud)

而已!

  • 如果将self.navigationController.interactivePopGestureRecognizer.delegate设置为self或nil,则会出现错误:从屏幕边缘轻扫,然后点击某些内容将视图控制器快速推入导航控制器,然后 - 1.当前视图控制器不响应任何触摸事件; 2.新视图控制器将不会显示; 3.再次从屏幕边缘滑动,将显示新的视图控制器; 4.调用popViewControllerAnimated:将动画参数设置为NO(点击自定义后退按钮),崩溃! (17认同)
  • 它看起来像*只是设置委托是不够的,请参阅@iwill的崩溃报告.我们找到的解决方法是存储原始委托,例如在`viewDidLoad`中,将自己设置为`viewDidAppear:`中的新委托,然后再将它重置为`viewDidDisappear:`中的原始委托.有点奇怪,但有效. (4认同)
  • 我不推荐这个解决方案.在呈现/弹出视图控制器时,它会导致一些错误. (4认同)
  • 谢谢,事实上将它设置为零也有效.我想知道这是不是一个bug? (3认同)
  • 你应该在viewDidAppear中设置它 - (void)viewDidAppear:(BOOL)animated {self.navigationController.interactivePopGestureRecognizer.delegate = self; } (2认同)

Nag*_*raj 16

简单解决方案

只需通过导航控制器设置导航栏的隐藏属性即可

只需使用这两行

self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.hidden = YES;
Run Code Online (Sandbox Code Playgroud)


小智 7

我用过这个. self.navigationController.interactivePopGestureRecognizer.delegate = self;

也在我的UINavigationController类中,在转换期间禁用interactivePopGestureRecognizer.

- (void)pushViewController:(UIViewController *)viewController
              animated:(BOOL)animated
{
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
}

    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        // disable interactivePopGestureRecognizer in the rootViewController of navigationController
        if ([[navigationController.viewControllers firstObject] isEqual:viewController]) {
            navigationController.interactivePopGestureRecognizer.enabled = NO;
        } else {
            // enable interactivePopGestureRecognizer
            navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在rootViewController中禁用interactivePopGestureRecognizer的原因是:当从rootViewController中的边缘滑动然后在下一个viewController中点击某些内容时,UI将不会接受任何触摸.按下主页按钮将应用程序置于后台,然后点击它进入前景...