简体   繁体   中英

swift xcode hide navigation bar for specific view

I want to hide the navigation bar for a specific view, and add my own custom "back button"

The way I am doing this now is by:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.navigationBarHidden = true
    }

It works but it takes 0.2 sec before the bar gets hidden, so you kinda can see it jump up once the view loads. Is there any other way to hide it?

我面临着同样的问题,使用以下方法可以解决此问题:

self.navigationController?.setNavigationBarHidden(true, animated: true)

Do it in the viewDidLoad for that view because the viewDidAppear runs once the view is shown to the user. You could also try setting the alpha of the navbar to 0 for faster action.

对于Swift 3:正如Arayman所指出的,将其添加到viewDidLoad中:

self.navigationController?.isNavigationBarHidden = true

just write this code in that swift file you want to hide the nav bar ... (Swift - 3)

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM