5

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?

2

4 Answers 4

4

I was facing the same issue, this was fixed using the following method:

self.navigationController?.setNavigationBarHidden(true, animated: true)
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

should I type "self.navigationController?.navigationBarHidden = true" or "navigationController?.navigationBarHidden = true" without "self." both works ?
@KiwoTew Without self i'd prefer. Both are the same cause you're writing the code within the class anyway!!!
0

For Swift 3: As Arayman Goes noted, add this to viewDidLoad:

self.navigationController?.isNavigationBarHidden = true

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.