由于某些原因,在新的集合视图组合布局中,部分头的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
}
orthogonalScrollingBehavior
设置为除.none
之外的其他值时,似乎会出现此问题。 - maxpower