您的位置:首页 > 其它

指定页面页面导航隐藏并开启页面滑动返回

2017-04-19 16:14 141 查看
指定页面隐藏导航条只需要实现下面两个方法
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

 这种方法隐藏导航条的同时系统的手势返回功能也会失效,如果想要手势返回的功能保留,有两种方案 。

一: 需要在 viewDidLoad方法中设置导航的 interactivePopGestureRecognizer 属性为YES 并设置 代理

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;      // 手势
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
// Do any additional setup after loading the view.

}

这样虽然能实现页面的滑动返回功能,但也带来一个严重的bug -.-返回到导航的 root控制器时由于滑动返回仍然存在,如果在root页面做同样的滑动返回手势再次push到隐藏导航的页面就回卡在root页面。。。当然有解决方法

在rootvc 的viewDidApper方法里面把滑动返回手势关掉

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
二: 在自定义导航控制器里实现如下代码
- (void)viewDidLoad {
[super viewDidLoad];

self.delegate = self;
self.popDelegate = self.interactivePopGestureRecognizer.delegate;
}

#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

if (viewController == self.viewControllers[0]) {
self.interactivePopGestureRecognizer.delegate = self.popDelegate;
}else {
self.interactivePopGestureRecognizer.delegate = nil;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: