Skip to content

Stretchy Header #47

Description

@Murodillo

I used stretchy Header FlowLayout
after import DisplaySwitcher my Header doesn't seem anymore?

import UIKit

class STCollectionViewFlowLayout: UICollectionViewFlowLayout {

override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
    return true
}

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
    
    let layoutAttributes = super.layoutAttributesForElements(in: rect)       
    
    layoutAttributes?.forEach({ (attributes) in
        if attributes.representedElementKind == UICollectionView.elementKindSectionHeader {
            guard let collectionView = collectionView else {
                return
            }

            let contentOffsetY = collectionView.contentOffset.y
            
            if contentOffsetY > 0 {
                return
            }
            let width = collectionView.frame.width
            let height: CGFloat = attributes.frame.height - contentOffsetY
            attributes.frame = CGRect(x: 0, y: contentOffsetY, width: width, height: height)

        }
    })
    return layoutAttributes
}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions