UICollectionView(QMUIKeyedHeightCache)

@interface UICollectionView (QMUIKeyedHeightCache)

UICollectionView 定义了一套动态计算 cell 高度的方式。 原理类似 UITableView,具体请参考 UITableView (QMUILayoutCell)。

  • 在 UICollectionView 不同的大小下会得到不一样的 QMUICellHeightCache 实例,从而保证大小变化时缓存自动刷新

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) QMUICellHeightCache *qmui_keyedHeightCache;

    Swift

    var qmui_keyedHeightCache: QMUICellHeightCache! { get }
  • 搭配 QMUICellHeightCache,清除指定 key 的高度缓存,注意请不要直接使用 [self.qmui_keyedHeightCache invalidateHeightForKey:],因为一个 UICollectionView 在不同宽度下会有不同的 QMUICellHeightCache,直接使用那个 cache 的 invalidate 方法只能刷新当前的 cache,无法刷新其他宽度下的 cache。

    Declaration

    Objective-C

    - (void)qmui_invalidateHeightForKey:(id<NSCopying>)key;

    Swift

    func qmui_invalidateHeight(forKey key: NSCopying!)