【发布时间】:2020-05-23 12:40:12
【问题描述】:
由于某些原因,在新的 collectionview 组合布局中,节标题的 zIndex 属性不起作用。我尝试了下面的代码来实现这种行为。
func configureCategorySectionLayout() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let layoutItem = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(80), heightDimension: .absolute(105))
let groupItem = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [layoutItem])
let sectionLayout = NSCollectionLayoutSection(group: groupItem)
let sectionItem = createAddressSectionHeader()
sectionItem.zIndex = 2
sectionItem.pinToVisibleBounds = true
sectionLayout.boundarySupplementaryItems = [sectionItem]
sectionLayout.contentInsets = .init(top: 0, leading: 10, bottom: 0, trailing: 10)
sectionLayout.orthogonalScrollingBehavior = .continuous
return sectionLayout
}
func createAddressSectionHeader() -> NSCollectionLayoutBoundarySupplementaryItem {
let sectionHeaderSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(65))
let sectionHeaderItem = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: sectionHeaderSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
return sectionHeaderItem
}
【问题讨论】:
-
面临同样的问题,您找到解决问题的方法了吗?
-
不,亲爱的...!! @PhM
-
当您将
orthogonalScrollingBehavior设置为.none以外的其他值时,似乎会发生这种情况
标签: ios swift uicollectionviewlayout swift5