user2636197 user2636197 - 8 months ago 74
iOS Question

Swift calling setNavigationBarHidden but view wont move to top

I am hiding my navigation bar when I scroll by calling:

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

The only problem is that the navbar doesnt get hidden all the way.

Whats even stranger is if I push to a new VC and go back and now try to scroll the navigation bar gets hidden all the way which is what I want.

If it matters I am hiding the navigation bar on VC2 then showing it when I exit back to VC 1.

enter image description here
This is what it looks when I try to hide the navbar first time, it doesnt go up all the way/underlying view showing too much.

enter image description here

If I push the to next VC and go back and now try to hide the navigationbar it works

The my view has a constraint of 0 to top layout so its hugging the top

So how can I make my view always be like in the second image when hiding my navigation bar?

Joe Joe

Try this code...

Note: This is a simple approach for your problem. If you want more custom look navBar and status bar look .You should read my previous comment...

Set navigation controller property hidesBarsOnSwipe to true

     override func viewDidAppear(animated: Bool) {

navigationController?.hidesBarsOnSwipe = true