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 中启用后退/左滑手势?
				
        
 
            
        基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
 - 如何将图像从一项活动发送到另一项活动? 2022-01-01
 - Play 商店的设备兼容性问题 2022-01-01
 - navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
 - 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
 - Android Volley - 如何动画图像加载? 2022-01-01
 - UIImage 在开始时不适合 UIScrollView 2022-01-01
 - SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
 - 如何比较两个 NSDate:哪个是最近的? 2022-01-01
 - Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				