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

iOS UICollectionView刷新時(shí)閃屏的解決方法

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

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

方法一:

[UIView performWithoutAnimation:^{ 
   //刷新界面 
    [self.collectionView reloadData]; 
 }]; 

把刷新界面的事件放在這個(gè)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簡(jiǎn)單方便。

上面說(shuō)的方法只能解決UIView的Animation,但是如果你的cell中還包含有CALayer的動(dòng)畫,比如這樣:

- (void)layoutSubviews{
  [super layoutSubviews];
  
  self.frameLayer.frame = self.frameView.bounds;
}

上述情況多用于自定義控件使用了layer.mask的情況,如果有這種情況,上面提到的方法是無(wú)法取消CALayer的動(dòng)畫的,但是解決辦法也很簡(jiǎn)單:

- (void)layoutSubviews{
  [super layoutSubviews];
  
  [CATransaction begin];
  [CATransaction setDisableActions:YES];
  
  self.frameLayer.frame = self.frameView.bounds;
  
  [CATransaction commit];  
}

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

相關(guān)文章

最新評(píng)論