UINavigationController隐藏后侧滑返回

2018-09-11  本文已影响0人  Sh1mmer

问题:当我们隐藏UINavigationController会发现,我们的侧滑返回就没有响应了.
解决问题:
首先我们新建一个BaseNavigationViewController继承UINavigationController.
用来作为我们的navigationController

BaseNavigationViewController.m中

@interface BaseNavigationViewController ()<UINavigationControllerDelegate>
@end

@implementation BaseNavigationViewController 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    self.interactivePopGestureRecognizer.delegate = (id)self.interactivePopGestureRecognizer;
}   
// 当控制器显示完毕的时候调用
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    //这里是为了防止在跟视图上侧滑出现的bug(具体什么原因也不知道);
    if (navigationController.viewControllers.count == 1) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }else{
        self.interactivePopGestureRecognizer.enabled = YES;
    }
}

到这基本就差不多了

上一篇 下一篇

猜你喜欢

热点阅读