Skip to content

UICollectionViewLayout

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

属性类型说明
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。

注意:以上属性中一部分在系统 UIKit 的语义上更常见于“布局属性对象”。这里以插件运行时实际暴露为准进行记录;如果你只在运行时把它当作数据结构读写,也完全可行。

方法参数返回值说明
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 清单

正在加载…

协议:,来源: