我有一个子类,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:在旋转过程中没有一个被击中。