14

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

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

- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
    return nil;
}

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

为什么这些方法会在边界更改时被调用,因为文档似乎没有建议它们这样做?文档似乎表明它们被称为与从集合视图中插入和删除项目有关。

有没有更好的方法来禁用旋转期间的交叉淡入淡出?

笔记:

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

1 回答 1

11

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.

这清楚地表明它们被称为边界变化。而不是删除/插入,“旧状态”和“新状态”似乎更准确。

于 2012-10-11T07:55:07.617 回答