iOS Development

ios – header disappears by lowering its top when scrolled up

I would love If you scroll, it doesn’t transfer downwards by lowering the peak on collectionview.

I need it in my utility, similar to in YouTube’s iOS utility, the place the header disappears by lowering its top when scrolled up.you possibly can see on video too
video:

https://youtu.be/Raz69tHhKdI

I wrote code like this

extension TemplatesViewController{
    func showTagsPlaceHolder() {
        DispatchQueue.essential.async { [self] in
            
            tagsPlaceHolderViewHeightAnchor.isActive = false
            tagsPlaceHolderViewHeightAnchor.fixed = 120
            tagsPlaceHolderViewHeightAnchor.isActive = true
            //tagsPlaceholder.isHidden = false
          
            
            self.view.setNeedsLayout()
            UIView.animate(withDuration: 0.5) {
                tagsPlaceholder.alpha = 1
                self.view.layoutIfNeeded()
            }
            
        }
      
        
    }
    func hideTagsPlaceHolder() {
        DispatchQueue.essential.async {[self] in
            
            tagsPlaceHolderViewHeightAnchor.isActive = false
            tagsPlaceHolderViewHeightAnchor.fixed = 0
            tagsPlaceHolderViewHeightAnchor.isActive = true
            
            self.view.setNeedsLayout()
            UIView.animate(withDuration: 0.5) {
                tagsPlaceholder.alpha = 0
                self.view.layoutIfNeeded()
            }
            
        }
       
    }
    
   
    
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        let yOffset = scrollView.contentOffset.y
        let maxOffsetY = scrollView.contentSize.top - scrollView.body.measurement.top;
        
        //refresh the desk view however disable the bounce
        if yOffset < 0.0 || yOffset > maxOffsetY{
            return
         }
     
         if (self.lastContentOffset > yOffset) {
              // transfer up
              print("transfer up")
              showTagsPlaceHolder()
              //tagsPlaceHolderIsHidden = true
              
          }
          else if (self.lastContentOffset < yOffset) {
              // transfer down
              print("transfer down")
              hideTagsPlaceHolder()
              //tagsPlaceHolderIsHidden = false
             
          }
          self.lastContentOffset = yOffset
        
       }
    
}

The one downside is that while you scroll up, the peak steadily decreases, or while you scroll down, the peak steadily will increase. It ought to be easy like YouTube

Credit: www.ismmailgsm.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button