欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS UICollectionView刷新時閃屏的解決方法

 更新時間:2017年11月23日 17:00:27   作者:隨風(fēng)  
本篇文章主要介紹了iOS UICollectionView刷新時閃屏的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

在做相冊的時候遇到了一個問題,就是UICollectionView刷新的時候會閃屏,網(wǎng)上搜了搜,解決的方法也是挺多,并沒有一一嘗試,只是存下來做個筆記,來看看遇到的幾種方法。

方法一:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論