在 UICollectionView/UICollectionViewLayout 旋转或边界更改上禁用交叉淡入淡出的最佳方法是什么? [英] What is the best best way to disable cross fades on UICollectionView/UICollectionViewLayout rotates or bounds changes?
问题描述
我有一个 UICollectionViewLayout
的子类,它将单元格放置在一个圆圈中.布局为调用 shouldInvalidateLayoutForBoundsChange:
返回 YES
.旋转时,初始位置的单元格淡出,最终位置的单元格淡入.
I have a subclass of UICollectionViewLayout
which places cells in a circle. The layout returns YES
for the call shouldInvalidateLayoutForBoundsChange:
. On rotation, the cell in the initial position fades out and the cell in the final position fades in.
通过将以下代码添加到我的布局中,我可以禁用淡入淡出和项目圈似乎只是随着方向的变化而旋转:
By adding the following code to my layout I can disable the fades and the circle of items appears to to simply rotate with the orientation change:
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
return nil;
}
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
为什么在边界更改时调用这些方法,因为文档似乎没有建议它们这样做?文档似乎表明它们被称为与从集合视图中插入和删除项目有关.
Why do the methods get called on a bounds change because documentation doesn't seem to suggest they do? Documentation seems to state they get called related to insertion and removal of items from the collection view.
有没有更好的方法来禁用旋转期间的交叉淡入淡出?
Is there a better way to disable the cross fade during rotation?
注意事项:
initialLayoutAttributesForAppearingItemAtIndexPath:
文档声明默认情况下该方法返回nil
但对super
的调用返回非零值.- 我在
UICollectionView
方法上设置了符号断点deleteItemsAtIndexPaths:
、moveItemAtIndexPath:toIndexPath:
和insertItemsAtIndexPaths:
并且在旋转过程中没有一个被命中.
- The
initialLayoutAttributesForAppearingItemAtIndexPath:
documentation states that by default the method returnsnil
but calls tosuper
returned non-nil values. - I set symbolic breakspoints on the
UICollectionView
methodsdeleteItemsAtIndexPaths:
,moveItemAtIndexPath:toIndexPath:
andinsertItemsAtIndexPaths:
and none of them are hit during rotation.
推荐答案
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.
这清楚地表明它们在边界变化时被调用.与移除/插入相比,旧状态"和新状态"似乎更准确.
which clearly says they are called on bounds changes. Rather than removal/insertion, "old state" and "new state" seems more accurate.
这篇关于在 UICollectionView/UICollectionViewLayout 旋转或边界更改上禁用交叉淡入淡出的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!