【问题标题】:UICollectionViewCompositionalLayout with group width smaller than the section width and pagingUICollectionViewCompositionalLayout 组宽度小于部分宽度和分页
【发布时间】:2021-02-23 17:06:37
【问题描述】:

我在每个尝试重新创建 AppStore 布局的教程中都看到了这种代码:

...
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.95), heightDimension: .absolute(300)), subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPaging
...

重要的部分是组小数宽度

我还注意到水平滚动该组时存在一些奇怪的滚动伪影:有时当我将第一个项目向左拖动并释放时,它只是跳回中心而没有动画。或者当我滚动到最后一项然后尝试向右滚动更多时,它只是弹回第一项。

这真的很奇怪,看起来像是 UICollectionViewCompositionalLayout 实现中的一个 bug 或者这个 + iOS 版本的组合。有没有人遇到过类似的问题,也许知道解决方法?我看到每种类型的分页都会发生这种情况。

编辑:我刚刚得知这个问题是 iOS 14 特有的,我在 iOS 13.7 模拟器上测试了我的应用程序,它在那里正常工作。

【问题讨论】:

    标签: uicollectionview uikit uicollectionviewlayout ios14 uicollectionviewcompositionallayout


    【解决方案1】:

    我在最后一项上向右滚动时遇到同样的问题,它会弹回倒数第二项。

    【讨论】:

    • 您找到解决方案了吗?我在最终组/页面上的反弹具有相同的行为。与 OP 非常相似,我使用的 fractionalWidth 小于 1(约 0.9)
    【解决方案2】:

    在我的情况下,我无法完全滚动到最后一项,因此我尝试为该组设置负尾随插入并且它起作用了:

    let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(55))
    let item = NSCollectionLayoutItem(layoutSize: itemSize)
        
    let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.75), heightDimension: .estimated(55 * 3 + 16))
    let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 3)
    group.interItemSpacing = .fixed(.centi)
    // Here
    group.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: -view.bounds.width * 0.25)
        
    let section = NSCollectionLayoutSection(group: group)
    section.orthogonalScrollingBehavior = .groupPaging
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      • 2017-07-05
      相关资源
      最近更新 更多