11
votes

I thought showing a screenshot would help understand the issue a bit better.

So the context is the following:

I'm in a navigation controller, on the settings screen of the app (which has a navigation item) and when we tap on the back button, we go back to the main screen of the app (for which I've hidden the navigation bar in the viewWillAppear of the main screen because I'm building a custom header view myself).

At soon as I tap on the back button, the navigation bar disappears immediately and I see a black rectangle appears instead until the animation to display the main screen is completed.

Do you know how I can avoid having this black rectangle appear?

Hope the questions makes sense.

Screenshots

Here is the initial settings screen:

enter image description here

When we tape on the back button, this happens... help :D

I know this piece of code is most likely responsible for the error, but I absolutely need to have the navigationBar hidden on the previous screen.

override func viewWillAppear(_ animated: Bool) {

navigationController?.isNavigationBarHidden = true

}

enter image description here

3
Have you tried the animated method of hiding the navigation bar setNavigationBarHidden(_ hidden: Bool, animated: Bool)? See docspaulvs
I'm glad it helped Edouard :-) On a side note, when you find that a comment answers a question, you can ask the commenter to post it as an answer and accept that. Just an idea, don't worry about it this time though.paulvs
Thanks. Oh right sorry about that. Please post this as the answer :) I'm deleting mine right away. I'm new to Stack in general, still learning the common practice. Thanks again.Edouard Barbier

3 Answers

19
votes

Have you tried the animated method of hiding the navigation bar setNavigationBarHidden(_ hidden: Bool, animated: Bool)?

8
votes

For Swift3.0

Add below code in First ViewController

override func viewWillAppear(_ animated: Bool) {
     super.viewWillAppear(true)
     navigationController?.setNavigationBarHidden(true, animated: animated)
}

Add below code in Second ViewController

func backButtonPressed() {
    navigationController?.setNavigationBarHidden(false, animated: false)
    navigationController?.popViewController(animated: true)
}
2
votes

Add below code in Second ViewController

the color can corresponding your custom

 override func viewWillAppear(_ animated: Bool) {
              self.navigationController?.view.backgroundColor = UIColor.white


        }