有的时候碰到detail页需要隐藏navigation bar的需求. 此时可用setNavigationBarHidden
方法来设置. 如下:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
用setNavigationBarHidden
方法时push和pop操作过度平滑. 但是发现侧滑退出功能已无效.
此时我们可以重写如下方法gestureRecognizerShouldBegin
.
- 在class上加上
UIGestureRecognizerDelegate
. - 设置
navigationController?.interactivePopGestureRecognizer?.delegate = self
- 增加如下函数:
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if(navigationController!.viewControllers.count > 1){
return true
}
return false
}
网友评论