Jevon Çøö Jevon Çøö - 1 month ago 15
iOS Question

NavigationBar Hides and Shows Depending on User Scroll direction IOS SWIFT

This idea has been driving em crazy as I haven't been able to find a suitable solution despite the multiple threads its created. so basically I want to be able to hide the

navigationbar
upon swipe, but I also want to be able to call it back upon an up swipe (like facebook ) and I want to do it without having to use any code from GitHub.

here's my idea of how to do such:

Get the direction in which a user is swiping on a screen (or in my case a
UIScrollView
with a
UITableView
inside) and if the direction is down, the
navigationbar
disappears and if the direction is up, the
navigationbar
slides back down. The only issue is that I don't see any clear way for doing this from a
UIScrollView
. can someone help me with a step by step of how such can be implemented?

Answer

Set navigation controller property hidesBarsOnSwipe to true

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    navigationController?.hidesBarsOnSwipe = true
}

You can also you also use third party library https://github.com/tristanhimmelman/HidingNavigationBar

You can read how to hide in apple developer documentation https://developer.apple.com/reference/uikit/uinavigationcontroller

Comments