4

In my app i have two view controllers embedded in navigation controller (lets say viewControllerA and viewControllerB). In the rootviewcontroller I don't want to show navigation bar, so in viewWillAppear and viewWillDisappear i have added thes lines:

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

override func viewWillDisappear(_ animated: Bool) {
            self.navigationController?.setNavigationBarHidden(false, animated: false)
        }

Now from the viewcontrollerB when back button is typed under navigation bar (when it starts to disapear) black view appears. How to remove that black view?

P.S. I have set navigation bar isTranslucent to false but it does not solve the problem. In my project i'm not using storyboards.

Vah.Sah
  • 522
  • 1
  • 6
  • 21
  • can you update with screenshot of your problem. – Joe Apr 26 '17 at 20:36
  • Sorry but I can not add screenshot because the black view appears when in navigation stack one view changes to another view, which is about 1 second (or less). So I can not take screenshot. The problem is that during navigation bar disappearance there are also black view back of navigation bar – Vah.Sah Apr 26 '17 at 20:45
  • How big is the black view.. check this post similar to your post http://stackoverflow.com/questions/42120482/navigation-bar-is-moving-up-to-statusbar/42909654#42909654 – Joe Apr 26 '17 at 20:55
  • I'm trying to replicate your issue from my test project.but it works as expected.may be the issue lies somewhere else.post your viewDidLoad code may help to find the solution. – Joe Apr 26 '17 at 21:11
  • I have created new test project and I have the same problem. Please take look on this (the test project) https://www.dropbox.com/s/gtaxmho70btjqjs/TestNav.zip?dl=0 – Vah.Sah Apr 26 '17 at 21:52
  • glad i helped.... – Joe Apr 26 '17 at 22:17

1 Answers1

5

Below answer based on the question owners test project.

From your test project you disabled the navigationController transition(view to view) animation when you hide and unhide navigation bar that causes the black view to appears.

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: true) // set to true
}

override func viewWillDisappear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: true) //set to true
}
Joe
  • 8,868
  • 8
  • 37
  • 59
  • Thanks for your help – Vah.Sah Apr 26 '17 at 22:16
  • 1
    Oh man, such a mistake.. I was fighting this issue for like half a day. In my case I just did `self.navigationController?.setNavigationBarHidden(true)`. adding animation prop solved it.. thank you @Joe – RameshVel Sep 19 '18 at 18:11