iOS 14.3 上的 UICollectionViewCompositionalLayout 错误 [英] UICollectionViewCompositionalLayout bug on iOS 14.3

查看:19
本文介绍了iOS 14.3 上的 UICollectionViewCompositionalLayout 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 UICollectionViewCompositionalLayoutUICollectionViewDiffableDataSource 结合的集合视图的 iOS 14.3 上遇到了一个奇怪的布局问题.问题是当您有一个正交部分之前有一个固有高度部分时,内部 _UICollectionViewOrthogonalScrollerEmbeddedScrollView 的位置错误.

I'm experiencing a weird layout issue on iOS 14.3 with collection views using a UICollectionViewCompositionalLayout combined in my case with the UICollectionViewDiffableDataSource. The issue is about the wrong position of the inner _UICollectionViewOrthogonalScrollerEmbeddedScrollView when you have an orthogonal section preceded by an intrinsic height section.

幸运的是,我能够非常轻松地重现该问题.考虑使用此数据源:

Fortunately I'm able to reproduce the issue very easily. Consider having this data source:

private var dataSource: UICollectionViewDiffableDataSource<Section, String>!

enum Section: Int, Hashable, CaseIterable {
    case first = 0
    case second = 1
}

为每个部分创建以下布局:

For each section you create the following layout:

private extension Section {
    var section: NSCollectionLayoutSection {
        switch self {
        case .first:
            let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(50))
            let item = NSCollectionLayoutItem(layoutSize: itemSize)
            let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(50))
            let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
            let section: NSCollectionLayoutSection = .init(group: group)
            return section
        case .second:
            let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
            let item = NSCollectionLayoutItem(layoutSize: itemSize)
            let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(200), heightDimension: .absolute(200))
            let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
            let section: NSCollectionLayoutSection = .init(group: group)
            section.orthogonalScrollingBehavior = .continuous
            section.contentInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)
            section.interGroupSpacing = 10
            return section
        }
    }
}

破坏布局的事情是将 itemSizegroupSize.estimated 一起放入 .first 部分高度.

The thing breaking the layout is having into the .first section both itemSize and groupSize with .estimated height.

您可以在 iOS 14.3 上看到下面的结果:乍一看布局在视觉上是正确的,但您立即意识到它已损坏,因为内部滚动视图位于错误的位置.这意味着在蓝色区域错误地发生了水平滚动.

You can see the result below on iOS 14.3: at the first glance the layout is visually correct, but you immediately realize the fact that it's broken because the inner scroll view is in the wrong place. This implies that the horizontal scroll happens wrongly in the blue area.

运行完全相同的代码直到 iOS 14.2,您将获得正确的布局.

Running exactly the same code up to iOS 14.2 you get the correct layout .

你怎么看这个问题?是我遗漏了什么还是可能是 UIKit 错误?

What do you think about this issue? Am I missing something or it could be a UIKit bug?

谢谢

推荐答案

对我来说,这个问题在 iOS 14.314.4 中可以重现.现在已在 iOS 14.5 beta1

For me this problem is reproducible in iOS 14.3 and 14.4 . And now is fixed in iOS 14.5 beta1

尝试安装最新的 Xcode beta 版本 12.5 beta 并使用运行 iOS 14.5

Try to install the latest Xcode beta version 12.5 beta and test it using a simulator running iOS 14.5

Xcode 测试版链接:https://developer.apple.com/download/

Xcode beta link: https://developer.apple.com/download/

这篇关于iOS 14.3 上的 UICollectionViewCompositionalLayout 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆