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

时间:2013-11-07 10:48:09

标签: uinavigationcontroller ios7 uinavigationbar uigesturerecognizer

我有一个嵌套在UINavigationController

中的视图控制器

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

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

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

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

我有什么遗失的吗?

5 个答案:

答案 0 :(得分:37)

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

self.navigationController.interactivePopGestureRecognizer.delegate = self;

就是这样!

答案 1 :(得分:16)

简单的解决方案

只需设置导航栏的隐藏属性,而不是通过导航控制器

只需使用这两行

self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.hidden = YES;

答案 2 :(得分: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;
        }
    }
}

在rootViewController中禁用interactivePopGestureRecognizer的原因是:当从rootViewController中的边缘滑动然后在下一个viewController中点击某些内容时,UI现在不会接受任何触摸。按home键将app放入后台,然后点击它进入前景...

答案 3 :(得分:3)

这对我来说似乎不起作用。我跟着Keithl的博文。这也没有奏效。

我最终与UISwipeGestureRecognizer达成了协议。它似乎做了它所说的。

UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(backButtonPressed:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.navigationController.view addGestureRecognizer:gestureRecognizer];

答案 4 :(得分:0)

将这两行添加到[val for sublist in risks for val in sublist] 为我工作。

-(void)viewDidAppear:(BOOL)animated

并且不要忘记将self.navigationController.navigationBarHidden = NO; self.navigationController.navigationBar.hidden = YES; 拨打到<UIGestureRecognizerDelegate>文件。

相关问题