本篇是對UICollectionViewLayout詳解的一個總結
補充:
當- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds返回YES的時候
- (UICollectionViewLayoutAttributes*)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
和 -
(UICollectionViewLayoutAttributes*)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
兩個方法也會對每個item調用一次,就會出現下圖看起來很亂的樣子,因為當bounds改變時,上述2個方法執行了插入/刪除的動畫。
所以在上述2個方法中,應該針對item到底是真的在顯示/消失,還是 UICollectionView 正在經歷的邊界改變動畫的不同情況,做出不同反應,并返回不同的布局屬性。