Skip to content

UICollectionViewLayout

UICollectionViewLayout 用于为 UICollectionView 计算布局信息。插件环境暴露了一组用于布局生命周期、注册 decoration view、查询布局属性与计算内容尺寸/目标偏移的成员。

UICollectionViewLayout类本身可见,但直接构造路径不稳定。实践上优先通过现有UICollectionView实例读取collectionViewLayout,不要在插件里直接新建布局实例。

在插件里做首版网格列表时,优先使用UICollectionViewFlowLayout并设置固定itemSize/sectionInset/minimumLineSpacingsizeForItemAtIndexPath这类动态尺寸路径在JS桥接里风险较高,后置。

属性类型说明
invalidateEverythingboolean只读。表示一次失效是否影响所有布局。
invalidateDataSourceCountsboolean只读。表示数据源计数是否需要重新计算。
indexPathAfterUpdateNSIndexPath只读。更新后的 indexPath(用于动画/过渡场景)。
indexPathBeforeUpdateNSIndexPath只读。更新前的 indexPath(用于动画/过渡场景)。
collectionViewUICollectionView只读。当前所属的 collectionView。
representedElementKindstring只读。元素 kind 标识。
indexPathNSIndexPathindexPath。
frame{ x: number, y: number, width: number, height: number }frame。
bounds{ x: number, y: number, width: number, height: number }bounds。
size{ width: number, height: number }size。
center{ x: number, y: number }center。
transformobject二维仿射变换。
transform3Dobject三维变换。
alphanumber透明度。
hiddenboolean是否隐藏。
zIndexnumberzIndex。

注意:本页记录的是 JSBUICollectionViewLayout 已导出的属性与方法。插件中按本页清单调用,不再扩展解释为其它对象语义。

方法参数返回值说明
invalidateLayout()void标记布局失效,触发重新计算。
registerClassForDecorationViewOfKind(viewClass, decorationViewKind)viewClass: id, decorationViewKind: stringvoid注册 decoration view 类型。
prepareLayout()void布局准备阶段回调。
layoutAttributesForElementsInRect(rect)rect: { x: number, y: number, width: number, height: number }NSArray返回 rect 内元素的布局属性数组。
layoutAttributesForItemAtIndexPath(indexPath)indexPath: NSIndexPathUICollectionViewLayoutAttributes | null返回指定 item 的布局属性。
layoutAttributesForSupplementaryViewOfKindAtIndexPath(kind, indexPath)kind: string, indexPath: NSIndexPathUICollectionViewLayoutAttributes | null返回指定 supplementary view 的布局属性。
layoutAttributesForDecorationViewOfKindAtIndexPath(decorationViewKind, indexPath)decorationViewKind: string, indexPath: NSIndexPathUICollectionViewLayoutAttributes | null返回指定 decoration view 的布局属性。
shouldInvalidateLayoutForBoundsChange(newBounds)newBounds: { x: number, y: number, width: number, height: number }booleanbounds 变化时是否需要失效布局。
targetContentOffsetForProposedContentOffsetWithScrollingVelocity(proposedContentOffset, velocity)proposedContentOffset: { x: number, y: number }, velocity: { x: number, y: number }{ x: number, y: number }根据目标偏移与滚动速度修正最终停靠位置。
targetContentOffsetForProposedContentOffset(proposedContentOffset)proposedContentOffset: { x: number, y: number }{ x: number, y: number }根据目标偏移修正最终停靠位置。
collectionViewContentSize(){ width: number, height: number }返回内容尺寸。
成员返回值说明
layoutAttributesClass()Class返回布局属性类。
invalidationContextClass()Class返回失效上下文类。
头文件 API 清单

正在加载…

协议:,来源: