Skip to content

Stretchy Header #47

@Murodillo

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
}

}

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