Search code examples
iosswiftuinavigationcontrolleruinavigationbaruinavigationitem

ios swift - navigation item background turns black when going back to a screen where the navigation bar is hidden


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


Solution

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