本篇文章主要介绍了iOS UICollectionView刷新时闪屏的解决方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
在做相册的时候遇到了一个问题,就是UICollectionView刷新的时候会闪屏,网上搜了搜,解决的方法也是挺多,并没有一一尝试,只是存下来做个笔记,来看看遇到的几种方法。
方法一:
[UIView performWithoutAnimation:^{
//刷新界面
[self.collectionView reloadData];
}];
把刷新界面的事件放在这个BLock里就可以了!
方法二
[UIView animateWithDuration:0 animations:^{
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:nil];
}];
方法三
[UIView setAnimationsEnabled:NO];
[self.trackPanel performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:^(BOOL finished) {
[UIView setAnimationsEnabled:YES];
}];
如果你的APP只支持iOS7+,推荐使用第一种方式performWithoutAnimation简单方便。
上面说的方法只能解决UIView的Animation,但是如果你的cell中还包含有CALayer的动画,比如这样:
- (void)layoutSubviews{
[super layoutSubviews];
self.frameLayer.frame = self.frameView.bounds;
}
上述情况多用于自定义控件使用了layer.mask的情况,如果有这种情况,上面提到的方法是无法取消CALayer的动画的,但是解决办法也很简单:
- (void)layoutSubviews{
[super layoutSubviews];
[CATransaction begin];
[CATransaction setDisableActions:YES];
self.frameLayer.frame = self.frameView.bounds;
[CATransaction commit];
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:iOS UICollectionView刷新时闪屏的解决方法
基础教程推荐
猜你喜欢
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- Android多返回栈技术 2023-04-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Flutter手势密码的实现示例(附demo) 2023-04-11
- Android中的webview监听每次URL变化实例 2023-01-23
- iOS开发教程之XLForm的基本使用方法 2023-05-01
