Layout类中,有3个方法是必定会被依次调用:

  1. prepareLayout: 准备所有view的layoutAttribute信息

  2. collectionViewContentSize: 计算contentsize,显然这一步得在prepareLayout之后进行

  3. layoutAttributesForElementsInRect: 返回在可见区域的view的layoutAttribute信息,

    这个方法不写 集合视图显示不出来,这个方法是将保存的每个item的信息告诉集合视图,进行显示。

 

此外,还有其他方法可能会被调用:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { } 
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { } 
- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)decorationViewKind atIndexPath:(NSIndexPath *)indexPath { } 
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { }

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-09-22
  • 2021-06-28
猜你喜欢
  • 2021-09-25
  • 2022-01-19
  • 2022-12-23
  • 2021-06-15
  • 2021-07-19
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案