2

我使用 CompositionalLayout 和 DiffableDatasource API 创建了一个 UICollectionView。除了向上移动的 Orthogonal ScrollView 之外,一切都按预期工作并且看起来像预期的那样。

以下屏幕截图显示了我的视图层次结构的相关部分。突出显示的视图是 UICollectionViewOrthogonalScrollerEmbeddedScrollView,如您所见,它的大小似乎正确,但沿 y 轴的位置不正确。

查看层次结构快照

除了在布局的错误区域中识别出滚动手势之外,上面的标题元素中的按钮也无法访问,因为它被所述滚动视图挡住了。

这是我的 NSCollectionLayoutSection 的定义:

            let fractionalGroupWidth: CGFloat = 0.85
            
            //Define Item Size
            let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(60))
            let item1 = NSCollectionLayoutItem(layoutSize: itemSize, supplementaryItems: [UICollectionView.getSeparatorSupplementaryItem(ofKind: "Separator1", withLeadingOffset: 72, forAbsoluteWidth: self.collectionView.frame.width*fractionalGroupWidth)])
            let item2 = NSCollectionLayoutItem(layoutSize: itemSize, supplementaryItems: [UICollectionView.getSeparatorSupplementaryItem(ofKind: "Separator2", withLeadingOffset: 72, forAbsoluteWidth: self.collectionView.frame.width*fractionalGroupWidth)])
            let item3 = NSCollectionLayoutItem(layoutSize: itemSize)
            
            //Define Group Size
            let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(fractionalGroupWidth), heightDimension: .estimated(180))
            let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item1, item2, item3])
            group.interItemSpacing = .fixed(12)
            
            let section = NSCollectionLayoutSection(group: group)
            section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)
            section.interGroupSpacing = 16
            section.orthogonalScrollingBehavior = .groupPaging
            
            if sectionData.title != nil || sectionData.shortTitle != nil{
                let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(40))
                let headerElement = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
                section.boundarySupplementaryItems = [headerElement]
            }
            
            return section

我尝试将单个项目以及组的高度尺寸从小数值更改为估计值或绝对值,并尝试调整 contentInsets。以上都对scrollView没有任何影响。

4

0 回答 0