Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stretchy Header #47

Open
Murodillo opened this issue Dec 23, 2019 · 0 comments
Open

Stretchy Header #47

Murodillo opened this issue Dec 23, 2019 · 0 comments

Comments

@Murodillo
Copy link

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
}

}

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

No branches or pull requests

2 participants