设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势? [英] How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem?

查看:18
本文介绍了设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 这里得到了相反的问题.iOS7 默认情况下,UINavigationController 堆栈的向后滑动手势可以弹出呈现的ViewController.现在我只是统一了所有 ViewControllers 的所有 self.navigationItem.leftBarButtonItem 样式.

I got the opposite issue from here. By default in iOS7, back swipe gesture of UINavigationController's stack could pop the presented ViewController. Now I just uniformed all the self.navigationItem.leftBarButtonItem style for all the ViewControllers.

代码如下:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:LOADIMAGE(@"back_button") style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];

之后,navigationController.interactivePopGestureRecognizer 被禁用.如何在不删除自定义 leftBarButtonItem 的情况下启用弹出手势?

after that, the navigationController.interactivePopGestureRecognizer is disabled. How could I make the pop gesture enabled without removing the custom leftBarButtonItem?

谢谢!

推荐答案

在viewDidLoad中首先设置委托:

First set delegate in viewDidLoad:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

然后在推送时禁用手势:

And then disable gesture when pushing:

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

并在 viewDidDisappear 中启用:

And enable in viewDidDisappear:

self.navigationController.interactivePopGestureRecognizer.enabled = YES;

另外,将 UINavigationControllerDelegate 添加到您的视图控制器.

Also, add UINavigationControllerDelegate to your view controller.

这篇关于设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆