0

I have a UIViewController that contains a UICollectionView pinned to all edges of the view. This view controller is inside a UINavigationController.

I want to gradually hide the navigation bar as I scroll down in the collection view. At the point that I have scrolled the distance of the height of the nav bar, the nav bar should be completely hidden. If I scroll back up it should gradually show the nav bar.

I have tried all the open source navigation bars on github, but none of them work correctly with iOS 12.

How can I achieve this?

Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • There is nothing available out of the box.. Might need to build a custom navigation bar and use `viewDidScroll` delegate of UIScrollView to compute the hiding and showing. – Harsh Nov 07 '18 at 18:26
  • Possible duplicate of [Hide NavigationBar when scrolling tableView in CollectionView?](https://stackoverflow.com/questions/37986923/hide-navigationbar-when-scrolling-tableview-in-collectionview) – Harsh Nov 07 '18 at 18:28
  • @Harsh It's the "computing the hiding and showing" that I'm unsure of. All the answers in the linked question don't work. I want it exactly how the animation of `AMScrollingNavbar` in the top answer works but that framework doesnt work properly with iOS 11+. – Tometoyou Nov 08 '18 at 10:38
  • Fork it and make it work for iOS 11. :) – Harsh Nov 08 '18 at 15:37

1 Answers1

0

UICollectionView is a subclass of UIScrollView and therefore you have access to its scrollViewDidScroll delegate method. Your UIViewController is also owned by its navigation controller, so you can create an instance property in the view controller, like navigationDelegate: UINavigationController?, that will act as a delegate. In the navigation controller, set that property equal to self and manipulate the nav bar however you want through the scroll delegate. Absolutely no need for third-party scripting for something this standard and basic.

trndjc
  • 11,654
  • 3
  • 38
  • 51