Swift UICollectionView带有pinToVisibleBounds的合成版面标题奇怪地被单元格遮住了

Swift UICollectionView带有pinToVisibleBounds的合成版面标题奇怪地被单元格遮住了,swift,cocoa-touch,uicollectionview,uicollectionviewlayout,uicollectionviewcompositionallayout,Swift,Cocoa Touch,Uicollectionview,Uicollectionviewlayout,Uicollectionviewcompositionallayout,我正在使用UICollectionView合成布局,希望有一个粘贴到顶部的标题 这应该是可能的 header.pinToVisibleBounds = true 然而,在滚动过程中,标题奇怪地变得模糊,看起来像一个bug。。。此外,重新加载时,看起来只有位于可见屏幕之外的单元格遮住了标题 你可以在这个视频中看到 这就是整个布局的构建方式 func buildLayout() -> UICollectionViewCompositionalLayout { // cells

我正在使用UICollectionView合成布局,希望有一个粘贴到顶部的标题

这应该是可能的

header.pinToVisibleBounds = true
然而,在滚动过程中,标题奇怪地变得模糊,看起来像一个bug。。。此外,重新加载时,看起来只有位于可见屏幕之外的单元格遮住了标题

你可以在这个视频中看到

这就是整个布局的构建方式

func buildLayout() -> UICollectionViewCompositionalLayout {

    // cells
    let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.5), heightDimension: .absolute(90))
    let item = NSCollectionLayoutItem(layoutSize: itemSize)
    item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)

    let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(90))
    let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: 2)
    group.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20)
    group.interItemSpacing = .fixed(10)

    let section = NSCollectionLayoutSection(group: group)
    section.interGroupSpacing = 10
    section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 0, bottom: 20, trailing: 0)

    // header
    let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200))
    let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
    header.pinToVisibleBounds = true
    header.zIndex = Int.max
    section.boundarySupplementaryItems = [header]

    let configuration = UICollectionViewCompositionalLayoutConfiguration()
    return UICollectionViewCompositionalLayout(section: section, configuration: configuration)
}
解决方法是什么?或者,还有什么方法可以使用“浮动”标题?


注1: 当标题附加到
configuration.boundarySupplementaryItems
时,它的行为与预期的一样。。。虽然这可能是当前案例的解决方案,但它并不能解决第节的总体问题。。。(还必须将zIndex设置为非常高的数字)


我一直在尝试实现一个
.leading
粘性标题,垂直布局,正交滚动将在标题上滚动。你的变通方法也适用于我的问题。我甚至不知道这个配置有
boundarySupplementaryItems
,很好。
do {
    center.contentInsets.top = 0
    let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200))
    let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
    header.pinToVisibleBounds = true
    header.zIndex = Int.max // !!! IMPORTANT
    //header.extendsBoundary = true
    configuration.boundarySupplementaryItems = [header]
}