AlignedCollectionViewFlowLayout icon indicating copy to clipboard operation
AlignedCollectionViewFlowLayout copied to clipboard

Top Alignment Bug

Open sjacs5537 opened this issue 4 years ago • 0 comments

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)

sjacs5537 avatar Jan 21 '21 09:01 sjacs5537