UICollectionViewLayout何时layoutAttributesForItemAtIndexPath调用

问题描述:

我是继承UICollectionViewLayout,并且layoutAttributesForItemAtIndexPath:方法永远不会被调用。UICollectionViewLayout何时layoutAttributesForItemAtIndexPath调用

我知道也可以覆盖layoutAttributesForElementsInRect:,但我宁愿不必处理矩形,因为如果我只处理索引路径会简单得多。

如果layoutAttributesForItemAtIndexPath:从来没有被调用过,它有什么意义呢?

layoutAttributesForItemAtIndexPath:实际上是在更改动画参数设置为true的布局时调用的。

layoutAttributesForItemAtIndexPath:被称为在不同scenarii,当你添加新的细胞来收集观点,当你改变布局,当你重新加载特定的索引路径等

你需要实现它,即使它赢了不会在“默认”情况下被调用。

我在想这个,因为我希望layoutAttributesForElementsInRect:会叫layoutAttributesForItemAtIndexPath:。但事实并非如此。

如果你想确保返回的布局属性始终修改,在这里看到我的回答: UICollectionViewLayout layoutAttributesForElementsInRect and layoutAttributesForItemAtIndexPath