您好,登錄后才能下訂單哦!
在做相冊的時候遇到了一個問題,就是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)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。