此布局会在集合视图更新时调整内容偏移量。 您可以插入、删除或重新加载项目,StableCollectionViewLayout
会处理内容偏移量。
像这样
您只需创建并将 StableCollectionViewFlowLayout
传递给 UICollectionView
的初始化方法即可
import StableCollectionViewLayout
UICollectionView(frame: .zero, collectionViewLayout: StableCollectionViewFlowLayout())
此外,您还可以创建 StableCollectionViewLayout
的自定义子类并使用它。
首选的安装方法是使用 CocoaPods。 将以下内容添加到您的 Podfile
中
pod 'StableCollectionViewLayout', '~> 1.0.2'
对于 Carthage,将以下内容添加到您的 Cartfile
中
github "aimalygin/StableCollectionViewLayout" ~> 1.0.2
To integrate using Xcode:
File -> Swift Packages -> Add Package Dependency
Enter package URL: https://github.com/aimalygin/StableCollectionViewLayout, and select the latest release.