Hide NavigationBar when scrolling tableView in CollectionView?

前端 未结 6 1603
一整个雨季
一整个雨季 2020-12-05 11:47

I have collectionViewController and collectionViewCell include TableView.CollectionView is horizontal layout.I want hide navigationbar when scroll the tableView. Is there an

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 12:38

     func scrollViewDidScroll(_ scrollView: UIScrollView)
           {
               //  var navigationBarFrame   = self.navigationController!.navigationBar.frame
               let currentOffset = scrollView.contentOffset
    
               if (currentOffset.y > (self.lastContentOffset?.y)!) {
                   if currentOffset.y > 0 {
                       initial = initial - fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y))
                   }
                   else if scrollView.contentSize.height < scrollView.frame.size.height {
                       initial = initial + fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y))
                   }
               }
               else {
                   if currentOffset.y < scrollView.contentSize.height - scrollView.frame.size.height {
                       initial = initial + fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y))
                   }
                   else if scrollView.contentSize.height < scrollView.frame.size.height && initial < maxPlus {
                       initial = initial - fabs(CGFloat(currentOffset.y - self.lastContentOffset!.y))
                   }
               }
    
               if (initial <= maxMinus){
                   initial =  maxMinus
                   self.tableviewTopConstrin.constant = 0
                   UIView.animate(withDuration: 0.4, animations: {
                       self.view.layoutIfNeeded()
                   })
    
               }else if(initial >= maxPlus){
                   initial = maxPlus
                   self.tableviewTopConstrin.constant = 70
                   UIView.animate(withDuration: 0.4, animations: {
                       self.view.layoutIfNeeded()
                   })
               }else{
               }
               self.lastContentOffset = currentOffset;
           }
    

提交回复
热议问题