1、首页签协议
UINavigationControllerDelegate
2、设置代理
self.navigationController.delegate = self;
3、实现协议方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
BOOL hide = NO;
if ([viewController isKindOfClass: [需要隐藏的VC class]]) {
hide = YES;
}
[self.navigationController setNavigationBarHidden: hide animated: animated];
}
以上即可实现navigationBar顺滑的隐藏与显示,不过左滑pop手势会失效,GitHub上有许多优秀的pop手势三方可以借鉴,也可以简单的如下实现
1、签协议
<UIGestureRecognizerDelegate>
2、设置手势、代理
UIPanGestureRecognizer *popPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.interactivePopGestureRecognizer.delegate action:NSSelectorFromString(@"handleNavigationTransition:")];
popPanGesture.delegate = self;
[self.view addGestureRecognizer: popPanGesture];
3、实现协议方法
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
if (self.navigationController.viewControllers.count <= 1){
return NO;
}
else{
return YES;
}
}