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

Top Alignment Bug #31

Open
sjacs5537 opened this issue Jan 21, 2021 · 0 comments
Open

Top Alignment Bug #31

sjacs5537 opened this issue Jan 21, 2021 · 0 comments

Comments

@sjacs5537
Copy link

sjacs5537 commented Jan 21, 2021

Hi,

I have a collectionView with vertical flow layout that contains the header and shows two cells in a row, the following code will return incorrect y pos in one of the cell:

Line 303:

 switch verticalAlignment {
         case .top:
            let minY = layoutAttributes.reduce(CGFloat.greatestFiniteMagnitude) { min($0, $1.frame.minY) }
            return AlignmentAxis(alignment: .top, position: minY)

I found out the issue is caused by the UICollectionElementKindSectionHeader contains in the layoutAttributes array and affected the result of minY.

Here is my quick fix:

let filteredLayoutAttributes = layoutAttributes.filter { layoutAttribute in
       return layoutAttribute.representedElementCategory == .cell
}
            
let minY = filteredLayoutAttributes.reduce(CGFloat.greatestFiniteMagnitude) { min($0, $1.frame.minY) }
return AlignmentAxis(alignment: .top, position: minY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant