How to hide a navigation bar from first ViewController in Swift?

前端 未结 12 1595
悲哀的现实
悲哀的现实 2020-11-30 17:03

How can I hide a navigation bar from first ViewController or a particular ViewController in swift?

I used the following code in viewDidLoad():

12条回答
  •  孤城傲影
    2020-11-30 17:06

    Swift 3

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        // Hide the navigation bar on the this view controller
        self.navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    
        // Show the navigation bar on other view controllers
        self.navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    

提交回复
热议问题