How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem?(设置 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 中启用后退/左滑手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势?
- URL编码Swift iOS 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- GPS状态的广播接收器? 2022-01-01
