aznelite89 aznelite89 - 17 days ago 13
Swift Question

setNavigationBarHidden not working from other class (Swift 3.0)

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!

Joe Joe
Answer

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)    
     }
Comments