RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
iOSUICollectionView刷新时闪屏的解决方法

在做相册的时候遇到了一个问题,就是UICollectionView刷新的时候会闪屏,网上搜了搜,解决的方法也是挺多,并没有一一尝试,只是存下来做个笔记,来看看遇到的几种方法。

创新互联主营马鞍山网站建设的网络公司,主营网站建设方案,重庆App定制开发,马鞍山h5重庆小程序开发搭建,马鞍山网站营销推广欢迎马鞍山等地区企业咨询

方法一:

[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];  
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


本文标题:iOSUICollectionView刷新时闪屏的解决方法
转载源于:http://sczitong.cn/article/gccjps.html