在 reloadItemsAtIndexPaths 后避免 UICollectionView 的动画 [英] Avoid animation of UICollectionView after reloadItemsAtIndexPaths

查看:22
本文介绍了在 reloadItemsAtIndexPaths 后避免 UICollectionView 的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UICollectionView 在 reloadItemsAtIndexPaths 被调用后动画项目(淡入淡出动画).

UICollectionView animate items after reloadItemsAtIndexPaths is called (fade animation).

有没有办法避免这个动画?

Is there a way to avoid this animation?

iOS 6

推荐答案

值得注意的是,如果您面向 iOS 7 及更高版本,则可以使用新的 UIView 方法 performWithoutAnimation:.我怀疑在幕后,这与此处的其他答案大致相同(暂时禁用 UIView 动画/核心动画操作),但语法很好且干净.

It's worth noting that if you're targeting iOS 7 and above, you can use the new UIView method performWithoutAnimation:. I suspect that under the hood this is doing much the same as the other answers here (temporarily disabling UIView animations / Core Animation actions), but the syntax is nice and clean.

所以对于这个问题,特别...

So for this question in particular...

目标 C:

[UIView performWithoutAnimation:^{
    [self.collectionView reloadItemsAtIndexPaths:indexPaths];
}];


斯威夫特:

UIView.performWithoutAnimation {
    self.collectionView.reloadItemsAtIndexPaths(indexPaths)
}


当然,此原则适用于您希望确保更改 动画化的任何情况.


Of course this principle can be applied for any situation that you want to ensure a change is not animated.

这篇关于在 reloadItemsAtIndexPaths 后避免 UICollectionView 的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆