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

查看:361
本文介绍了如何在设置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;

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

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