当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS UICollectionView刷新时闪屏的解决方法

iOS UICollectionView刷新时闪屏的解决方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

坐上火车去拉萨伴奏,百诺摄影包,嘉善团

在做相册的时候遇到了一个问题,就是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];  
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网