4
class StretchyHeader: UICollectionViewFlowLayout {

    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {

        let layoutAttributes = super.layoutAttributesForElements(in: rect)! as [UICollectionViewLayoutAttributes]
        let contentOffset = collectionView!.contentOffset

        if (contentOffset.y < 0) {
            let deltaY = abs(contentOffset.y)
            for attributes in layoutAttributes where  attributes.representedElementKind == UICollectionView.elementKindSectionHeader {
                var frame = attributes.frame
                    frame.size.height =  headerReferenceSize.height + deltaY
                    frame.origin.y = frame.minY - deltaY
                    attributes.frame = frame
            }
        }

        return layoutAttributes
    }

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

}

Trying to implement this to a compositional layout, but so far no good. How can I achieve this in a compositional layout?

skylin
  • 51
  • 4

0 Answers0