什么是禁用UICollectionView / UICollectionViewLayout旋转或界限更改的交叉淡化的最佳方法?

我有一个UICollectionViewLayout的子类放置单元格在一个圆圈。 对于调用shouldInvalidateLayoutForBoundsChange:布局返回YES 。 旋转时,初始位置的单元淡出,最后位置的单元淡入。

通过将下面的代码添加到我的布局中,我可以禁用淡入淡出,项目的圆圈似乎只是随着方向更改而旋转:

 - (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { return nil; } - (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { return [self layoutAttributesForItemAtIndexPath:itemIndexPath]; } 

为什么这些方法会被调用,因为文档似乎没有提示他们呢? 文档似乎声明他们被调用与从集合视图中插入和移除项目有关。

有没有更好的方法来禁用旋转过程中的交叉淡入淡出?

笔记:

  • initialLayoutAttributesForAppearingItemAtIndexPath:文档指出,默认情况下,该方法返回nil但调用super返回的非零值。
  • 我在UICollectionView方法deleteItemsAtIndexPaths:moveItemAtIndexPath:toIndexPath:insertItemsAtIndexPaths:上设置了符号断点,并且在旋转过程中都没有命中它们。

UICollectionViewLayout.h文件状态

 // This set of methods is called when the collection view undergoes an animated transition such as a batch update block or an animated bounds change. // For each element on screen before the invalidation, finalLayoutAttributesForDisappearingXXX will be called and an animation setup from what is on screen to those final attributes. // For each element on screen after the invalidation, initialLayoutAttributesForAppearingXXX will be called an an animation setup from those initial attributes to what ends up on screen. 

这清楚地表明,他们被称为边界的变化。 “旧国家”和“新国家”似乎更准确,而不是去除/插入。