0

I have already read this thread Hide NavigationBar when scrolling tableView in CollectionView?

but I still can't get what I want. I know that there is a pod that can do this, but I try to avoid using pod.

I want to hide the navigation bar when the user scroll down the table view, and I want the navigation bar back when the user scroll up back to the top. like in the "today" bar in the App Store.

I have tried to use

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationController?.hidesBarsOnSwipe = true
    }

it can hide the navigation bar when I scroll down the table view, but when I scroll up back to the top, the navigation bar still disappear.

you can see here is the .gif file that the I can't unhide the navigation bar back : http://g.recordit.co/zIW2DkCc6j.gif

here is the contraint of my table view enter image description here

what should I do ? or maybe you have other code ? please share :)

sarah
  • 3,819
  • 4
  • 38
  • 80
  • You want it to be completely hidden? – Tigran Iskandaryan Jun 17 '18 at 14:36
  • no, I want after I hide it, I want the navigation bar back when the user scroll up back to the top – sarah Jun 17 '18 at 14:37
  • The linked SO question has some solutions in it; which ones did you try and what about them did not match your requirements? Also, if there is a pod, did you have a look at the pod's source code? – dr_barto Jun 17 '18 at 14:54
  • Can you show the constraints for your table view? – Tigran Iskandaryan Jun 17 '18 at 14:56
  • @dr_barto yes there is a pod that can solve this, but I haven't seen it. it little bit weird since i saw tutorial on youtube that only use self.navigationController?.hidesBarsOnSwipe = true, but it can get the navigation bar back when scroll up back – sarah Jun 17 '18 at 15:04
  • @TigranIskandaryan, I have attached the screen shot of my contraints in my question above :) – sarah Jun 17 '18 at 15:04

1 Answers1

1

Ok. What you do is right (in code). Just change the top constraint of the table view to the following:

enter image description here

Tigran Iskandaryan
  • 1,371
  • 2
  • 14
  • 41