Storyboard - Hiding top bar of navigation controller programmatically

前端 未结 8 738
失恋的感觉
失恋的感觉 2020-12-13 14:11

I\'m using a storyboard and I\'m trying to hide a top bar of my main navigation controller when a certain button is pressed (or function is called). I know I have to initial

8条回答
  •  轮回少年
    2020-12-13 14:36

    The answers are correct. Just want to add that you probably want to put back the navigation bar when leaving the view as other views might use it and when you hide for one its hidden for all.

    override func viewDidLoad() {
            super.viewDidLoad()
            self.navigationController?.navigationBar.isHidden = true
        }
    

    and before you leave the view:

    override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          self.navigationController?.navigationBar.isHidden = false
    }
    

    `

提交回复
热议问题