gpt4 book ai didi

iphone - 在 UICollectionView/UICollectionViewLayout 旋转或边界更改时禁用淡入淡出的最佳方法是什么?

转载 作者:技术小花猫 更新时间:2023-10-29 10:17:06 25 4
gpt4 key购买 nike

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

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

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

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

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

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

注意事项:

  • 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.

这清楚地表明他们在边界变化时被调用。 “旧状态”和“新状态”似乎比删除/插入更准确。

关于iphone - 在 UICollectionView/UICollectionViewLayout 旋转或边界更改时禁用淡入淡出的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12649271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com