这是 UICollectionView/PSTCollection 的一个改进版
(1) 您可以通过调用以下方法让集合视图预载一个细胞或一个尚未在屏幕上的细胞屏幕:
// in Swift
if let flowLayout = collectionView.collectionViewLayout as? PSTCollectionViewFlowLayout {
flowLayout.preloadMask = .Below // or (.Above | .Below), or (.Left | .Right)
flowLayout.preloadAmount = .OneScreen // this is optional, by default it preloads one cell
}
(2) 当您调用 collectionView.reloadData 时,dequeueReusableCellWithReuseIdentifier:indexPath: 将尝试为您提供一个带有原始 indexPath 的细胞。所以如果您已经有一个加载的集合视图,只想添加更多数据或部分,您可以直接调用 reloadData,仅当代码 necessay 时在 cellForItemAtIndexPath 中渲染一个细胞(例如,通过比较附加到细胞的模型) thus 避免图像闪烁。这非常有用,因为当表格更复杂时,performBatchUpdates 和 insertItemsAtIndexPaths 的协调会更加困难。
感谢 Peter Steinberger 和原始 PSTCollectionView 项目的所有贡献者(steipete/PSTCollectionView)
PSTCollectionView 与 Xcode 4.5.2+ 和 ARC 兼容。
PSTCollectionView 需要QuartzCore.framework。
另一个目标(至少在调试中非常有用)是 UI/PST 类之间的互操作性
UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
PSTCollectionView *collectionView = [[PSTCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:(PSTCollectionViewFlowLayout *)flowLayout];
(*) 注意,对于某些方法,我们不能使用下划线 _ 变体,否则我们可能会在私有 API 使用上得到错误的正面结果。我添加了一些运行时黑客技术,用于动态添加对那些情况的块转发器(主要用于 UI/PST 互操作性)
PSTCollectionView 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。