如何快速隐藏第一个ViewController或特定ViewController的导航栏?
我在中使用了以下代码viewDidLoad():
viewDidLoad()
override func viewDidLoad() { super.viewDidLoad() self.navigationController?.isNavigationBarHidden = true }
以及viewWillAppear:
viewWillAppear
override func viewWillAppear(animated: Bool) { self.navigationController?.isNavigationBarHidden = true }
两种方法都对所有ViewController隐藏导航控制器。
如果您知道其他所有视图都应显示该栏,则可以viewWillDisappear将其重新设置为可见。
viewWillDisappear
在Swift中:
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.setNavigationBarHidden(true, animated: animated) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) navigationController?.setNavigationBarHidden(false, animated: animated) }