✔︎
navigationController?.navigationBar.isHidden = true
✘
navigationController?.isNavigationBarHidden = true
ControllerB 的生命周期方法中设置导航栏的显示与隐藏
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: true)
// 开启隐藏导航栏后的边缘侧滑返回
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
navigationController?.interactivePopGestureRecognizer?.delegate = self
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
ControllerB 中重新实现边缘侧滑返回的手势代理,实现 UIGestureRecognizerDelegate
协议
extension NewReminderController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
// 开启隐藏导航栏后的边缘侧滑返回
if gestureRecognizer == navigationController?.interactivePopGestureRecognizer {
return true
}
return true
}
}
iOS 11 后,手动设置 titleView
大小需要
覆盖 view 的方法
override var intrinsicContentSize: CGSize {
// return UILayoutFittingExpandedSize
return CGSize(width: 500, height: 50)
}
设置不使用自动布局
新建一个 view 之后,设置自动布局的属性
view.translatesAutoresizingMaskIntoConstraints = false
<#a navigation bar#>.navigationBar.shadowImage = UIImage()