iOS 13:UICollectionViewCompositionalLayout 的缓存?

Hel*_*imo 5 wwdc ios uicollectionview uicollectionviewlayout swift

在全新且非常整洁的情况下UICollectionViewCompositionalLayout- 如何UICollectionViewLayoutAttributes在初始创建时缓存?

\n\n

所有已知的方法和属性似乎都已内置,因为新的布局类继承自UICollectionViewLayout.

\n\n

回顾“旧的”自定义UICollectionViewLayout方法,据我所知,此类任务的路径是使用方法prepare()用定制的[UICollectionViewLayoutAttributes].

\n\n

根据我的理解,新的布局类会逐节创建布局,从我们在 WWDC19 演讲“集合视图布局的进展”-> NSCollectionLayoutSection中看到的方法中返回createLayout(). And it seems to do that only once at initialisation.

\n\n

现在,我对 a 进行了子类化UICollectionViewCompositionalLayout,并且layoutAttributesForElements该类按预期返回:

\n\n
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {\n        let superAttributes = super.layoutAttributesForElements(in: rect)\n        print("I am returning attributes: ", supersAttributes)\n        return superAttributes\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

但由于它们不是手动创建的,我在哪里可以最初一次性捕获这些属性以添加到缓存数组中?

\n\n

这条路径的原因是我试图重新创建一个非常非常高的collectionViewLayout,我需要它可缩放。而这(至少在过去)只能通过使用缓存、在 zion 期间修改缓存属性并layoutAttributesForElements(in: rect)在整个生命周期中从缓存返回来获得性能。\n我在 Ray Wenderlich\xc2\xb4s tuturials 和其他地方看到过一种技术。

\n\n

任何输入都会很棒!让我们来了解一下争论 CollectionViews 的新的、更简单的世界吧!

\n\n

非常感谢您的阅读。

\n