UICollectionView

@_spi(FW) extension UICollectionView
extension UICollectionView: SkeletonViewDataSource

UIKit+SkeletonView

StatisticalViewProtocol

Cache

  • 手工清空尺寸缓存,用于尺寸发生变化的情况

    Declaration

    Swift

    public func fw_clearSizeCache()
  • 指定key设置cell尺寸缓存,设置为zero时清除缓存

    Declaration

    Swift

    public func fw_setCellSizeCache(_ size: CGSize, for key: AnyHashable)
  • 指定key获取cell缓存尺寸,默认值automaticSize

    Declaration

    Swift

    public func fw_cellSizeCache(for key: AnyHashable) -> CGSize
  • 指定key设置ReusableView尺寸缓存,设置为zero时清除缓存

    Declaration

    Swift

    public func fw_setReusableViewSizeCache(_ size: CGSize, kind: String, for key: AnyHashable)
  • 指定key获取ReusableView缓存尺寸,默认值automaticSize

    Declaration

    Swift

    public func fw_reusableViewSizeCache(_ kind: String, for key: AnyHashable) -> CGSize

Cell

  • 获取 Cell 需要的尺寸,可固定宽度或高度,可指定key使用缓存

    Declaration

    Swift

    public func fw_size(
        cellClass: UICollectionViewCell.Type,
        width: CGFloat = 0,
        height: CGFloat = 0,
        cacheBy key: AnyHashable? = nil,
        configuration: (UICollectionViewCell) -> Void
    ) -> CGSize

    Parameters

    cellClass

    cell类

    width

    固定宽度,默认0不固定

    height

    固定高度,默认0不固定

    key

    使用 key 做缓存标识,如数据唯一id,对象hash等,默认nil

    configuration

    布局cell句柄,内部不会拥有Block,不需要__weak

    Return Value

    cell尺寸

ReusableView

  • 获取 ReusableView 需要的尺寸,可固定宽度或高度,可指定key使用缓存

    Declaration

    Swift

    public func fw_size(
        reusableViewClass: UICollectionReusableView.Type,
        width: CGFloat = 0,
        height: CGFloat = 0,
        kind: String,
        cacheBy key: AnyHashable? = nil,
        configuration: (UICollectionReusableView) -> Void
    ) -> CGSize

    Parameters

    reusableViewClass

    ReusableView class

    width

    固定宽度,默认0不固定

    height

    固定高度,默认0不固定

    kind

    ReusableView类型,Header 或者 Footer

    key

    使用 key 做缓存标识,如数据唯一id,对象hash等,默认nil

    configuration

    布局 ReusableView,内部不会拥有 Block,不需要 __weak

    Return Value

    ReusableView尺寸

UICollectionView+UIKit

  • reloadData完成回调

    Declaration

    Swift

    public func fw_reloadData(completion: (() -> Void)?)
  • reloadData禁用动画

    Declaration

    Swift

    public func fw_reloadDataWithoutAnimation()
  • 判断indexPath是否有效

    Declaration

    Swift

    public func fw_isValidIndexPath(_ indexPath: IndexPath) -> Bool
  • 计算指定indexPath的frame,并转换为指定视图坐标(nil时默认window)

    Declaration

    Swift

    public func fw_layoutFrame(at indexPath: IndexPath, to view: UIView?) -> CGRect?
  • 添加拖动排序手势,需结合canMove、moveItem、targetIndexPath使用

    Declaration

    Swift

    @discardableResult
    public func fw_addMovementGesture(customBlock: ((UILongPressGestureRecognizer) -> Bool)? = nil) -> UILongPressGestureRecognizer
  • 简单曝光方案,willDisplay调用即可,集合快速滑动、数据不变等情况不计曝光。如需完整曝光方案,请使用StatisticalView

    Declaration

    Swift

    public func fw_willDisplay(_ cell: UICollectionViewCell, at indexPath: IndexPath, key: AnyHashable? = nil, exposure: @escaping () -> Void)