-
Notifications
You must be signed in to change notification settings - Fork 203
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
Collection view header getting overlapped #40
Comments
The issue is that private func verticalAlignmentAxisForLine(
with layoutAttributes: [UICollectionViewLayoutAttributes]
) -> AlignmentAxis<VerticalAlignment>? {
let cellAttributes = layoutAttributes.filter {
return $0.representedElementCategory == .cell
}
guard let firstAttribute = cellAttributes.first
else {
return nil
}
let indexPath = firstAttribute.indexPath
switch verticalAlignment {
case .top:
let minY = cellAttributes.reduce(CGFloat.greatestFiniteMagnitude) {
min($0, $1.frame.minY)
}
return AlignmentAxis(
alignment: .top,
position: minY
)
case .bottom:
let maxY = cellAttributes.reduce(0) {
max($0, $1.frame.maxY)
}
return AlignmentAxis(
alignment: .bottom,
position: maxY
)
default:
let centerY = firstAttribute.center.y
return AlignmentAxis(
alignment: .center,
position: centerY
)
}
} fileprivate func isFrame(
for firstItemAttributes: UICollectionViewLayoutAttributes,
inSameLineAsFrameFor secondItemAttributes: UICollectionViewLayoutAttributes
) -> Bool {
guard let lineWidth = contentWidth
else
{
return false
}
let firstItemFrame = firstItemAttributes.frame
let lineFrame = CGRect(
x: sectionInset.left,
y: firstItemFrame.origin.y,
width: lineWidth,
height: firstItemFrame.size.height
)
return lineFrame.intersects(
secondItemAttributes.frame
)
} open override func layoutAttributesForSupplementaryView(
ofKind elementKind: String,
at indexPath: IndexPath
) -> UICollectionViewLayoutAttributes? {
let attributes = super.layoutAttributesForSupplementaryView(
ofKind: elementKind,
at: indexPath
)
return attributes
} private func setFrame(
forLayoutAttributes layoutAttributes: UICollectionViewLayoutAttributes
) {
if layoutAttributes.representedElementCategory == .cell { // Do not modify header views etc.
let indexPath = layoutAttributes.indexPath
if let newFrame = layoutAttributesForItem(
at: indexPath
)?.frame {
layoutAttributes.frame = newFrame
}
}
if layoutAttributes.representedElementKind == UICollectionView.elementKindSectionHeader {
let indexPath = layoutAttributes.indexPath
if let newFrame = layoutAttributesForSupplementaryView(
ofKind: UICollectionView.elementKindSectionHeader,
at: indexPath
)?.frame {
layoutAttributes.frame = newFrame
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Collection view header getting overlapped while setting
let alignedFlowLayout = collectionView?.collectionViewLayout as? AlignedCollectionViewFlowLayout
alignedFlowLayout?.horizontalAlignment = .left
alignedFlowLayout?.verticalAlignment = .top
The text was updated successfully, but these errors were encountered: