UICollectionViewCompositionalLayout 不会滚动到不完整的组

UICollectionViewCompositionalLayout doesn't scroll to incomplete group

我使用 UICollectionViewCompositionalLayout 进行了简单的实现。有两个部分,每个部分都有水平滚动的单行,部分中的每个项目都有整个容器宽度的 1/4(现在是全屏)。

我想要分页滚动,但是当数据源在该部分提供 [​​=22=]4n+1 元素时,我无法滚动访问最后一项。

如何像使用简单 UICollectionViewFlowLayout 一样用纯动画修复最后一项?

func createCollectionViewLayout() -> UICollectionViewLayout {
    UICollectionViewCompositionalLayout { sectionIndex, environment -> NSCollectionLayoutSection? in
        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1 / 4), heightDimension: .fractionalHeight(1))
        let item = NSCollectionLayoutItem(layoutSize: itemSize)

        let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalWidth(0.4))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: 4)

        let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(44))
        let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)

        let section = NSCollectionLayoutSection(group: group)
        section.orthogonalScrollingBehavior = .groupPaging
        section.boundarySupplementaryItems = [header]

        return section
    }
}

Video with bug example

经过复杂的研究:似乎是布局错误,一种可能的解决方案是根据项目的数量以编程方式更改 orthogonalScrollingBehavior