调用layoutAttributesForItemAtIndexPath时的UICollectionViewLayout

时间:2013-09-24 18:16:49

标签: ios uicollectionviewlayout

我是UICollectionViewLayout的子类,永远不会调用layoutAttributesForItemAtIndexPath:方法。

我知道也要覆盖layoutAttributesForElementsInRect:,但我宁愿不必处理rect,因为如果我只处理索引路径会更简单。

如果永远不会调用layoutAttributesForItemAtIndexPath:,那么它是什么意思?

3 个答案:

答案 0 :(得分:3)

当您在集合视图中添加新单元格,更改布局,重新加载特定索引路径等时,会在不同的场景中调用

layoutAttributesForItemAtIndexPath:

你需要实现它,即使它没有在"默认"中被调用。场景。

答案 1 :(得分:2)

在将动画参数设置为true的情况下更改布局时,实际上会调用

layoutAttributesForItemAtIndexPath:

答案 2 :(得分:0)

我自己也在想这个,因为我曾希望layoutAttributesForElementsInRect:会打电话给layoutAttributesForItemAtIndexPath:。但事实并非如此。

如果要确保始终修改返回的布局属性,请在此处查看我的答案: UICollectionViewLayout layoutAttributesForElementsInRect and layoutAttributesForItemAtIndexPath