1

I want to show the navigation bar when scroll the content to the top.

I am able to hide/show the navigation from ViewController but the "setNavigationBarHidden" not working when i calling from UIcollectionView class.

I have vertical UIcollectionView with horizontal UIcollectionView which on the ViewController. Now i am calling the hideBar() from vertical which is from another class as my VC has horizontal UIcollectionView:

I am calling the method as shown as below :-

FeedCell.swift (Vertical UICollectionView) enter image description here

HomeController.swift (ViewController which has two UICollectionView) enter image description here

enter image description here

Hierarchy of project

enter image description here

It seems like the FeedCell.swift able to access to HomeController but the navigationController?.setNavigationBarHidden is not working when i calling from FeedCell.swift.

Appreciated very much if anyone could give advise on this issue, thanks!

aznelite89
  • 2,025
  • 4
  • 21
  • 32
  • Why you can't simply use `navigationController?.hidesBarsOnSwipe = true` rather hiding a navigationBar...take a look at my answer http://stackoverflow.com/questions/40166065/swift-calling-setnavigationbarhidden-but-view-wont-move-to-top/40166897#40166897 . just call this func on both VC? – Joe Nov 17 '16 at 02:57
  • @Joe hidesBarsOnSwipe not working for my case , i think it probably due to i am using 2 level of UIcollectionview. When i have only 1 UICollectionView on my VC it was working – aznelite89 Nov 17 '16 at 03:08
  • 1
    This make no sense to me because navigationController is nothing to do with your collectionView it doesn't matter how many collectionView in that particular VC.can you post your mainStoryBoard hierarchy.so,everyone get better understanding of your problem? – Joe Nov 17 '16 at 03:13
  • @Joe i had post the hierarchy, basically my HomeController had a vertical UICollectionView. Within this horizontal UICollectionView, we had register the second UICollection which is vertical UICollectionView created in FeedCell.swift. – aznelite89 Nov 17 '16 at 03:50
  • @Joe the hideBarsOnSwipe is work but only when i scroll horizontally instead of vertically. So it is not working as expected. – aznelite89 Nov 17 '16 at 03:51
  • so you want to hide navigationBar when swipe up or down for firstCollectionView and swipe left or right to hide 2ndCollectionView is that what you want..let me know you have both collectionView in the same viewController? – Joe Nov 17 '16 at 03:57
  • @Joe i would like to hide navigationBar when scroll vertically on 2nd Collection View – aznelite89 Nov 17 '16 at 04:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128314/discussion-between-joe-and-aznelite89). – Joe Nov 17 '16 at 04:05

1 Answers1

3

Note: Below answer based on the conversation between the question owner and myself.

   func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

    if(velocity.y>0) {

     UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { 
     self.navigationController?.setNavigationBarHidden(true, animated: true) 
     }, completion: nil)

     } else {
     UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { 
     self.navigationController?.setNavigationBarHidden(false, animated: true)
     }, completion: nil)    
     }
Joe
  • 8,868
  • 8
  • 37
  • 59