0

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?

user2636197
  • 3,982
  • 9
  • 48
  • 69
  • Only way you can do this you have to tweak navigationBar setting and programmically create your own navigationBar and status bar using UIView and take it from there..it worked I am personally using in my project. – Joe Oct 21 '16 at 01:25
  • You half way right mate.I will upload the proper code.Once you post another question about how you want the animation etc...one more thing about my test project.you can even able to animate navBar and don't forgot to give me an upvote...cheers – Joe Oct 21 '16 at 03:13
  • thanks for the buzz..i will upload the code 2mrow...cheers – Joe Oct 21 '16 at 12:22
  • You should change your question content.otherwise you will get -ve feedback on your question.someone already gave you a-ve feedback.if I give you a answer for the question with more -Ve feedback.people think I'm crazy. Simply modify the question tag like how to hide a navBar and programmically place an uiview that looks like a navigationBar...cheers – Joe Oct 21 '16 at 14:05
  • Checkout my answer on this post http://stackoverflow.com/questions/40176803/swift-navigation-bar-background-color-white-does-not-work/40178657#40178657. Your code hidden on that answer...if you like it give me a tick cheers... – Joe Oct 21 '16 at 14:07

2 Answers2

1

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) {
super.viewDidAppear(animated)

navigationController?.hidesBarsOnSwipe = true

}

Joe
  • 8,868
  • 8
  • 37
  • 59
  • About your comment, do you mean that I should init my view with the navigationbar completley hidden and then style a UIView to make it look lika a navigation bar? – user2636197 Oct 21 '16 at 02:29
  • here is my new question: http://stackoverflow.com/questions/40175513/swift-hide-navigation-bar-on-scroll Would be nice to see how you animate – user2636197 Oct 21 '16 at 11:28
-1

I understand your question. The green part in your second image is not a navigation bar, it is a status bar. You can hide the status bar as below.

You should implement prefersStatusBarHidden on your view controller(s):

In Swift 2:

override func prefersStatusBarHidden() -> Bool { return true }

In Swift 3:

override var prefersStatusBarHidden: Bool { return true }

  • No the green is my view. I want my view to always appear like in the second image when I hide my navigation bar. I still want my status bar to be shown, I just dont want that extra space like in the first image – user2636197 Oct 21 '16 at 00:21
  • I cant since I am hiding the navigation bar when I scroll and not leaving – user2636197 Oct 21 '16 at 00:49