collectionView reloadData 引起闪屏

1.在dataSource赋值的时候:

注:model.mediumArr为加载进来的新数据源

NSMutableArray*indexPaths = [[NSMutableArray alloc] init];

 for ( inti =0; i < model.mediumArr.count;  i ++) {

          NSIndexPath *indexPath = [NSIndexPath indexPathForRow: self.dataSource.count+ i inSection: 0];

           [indexPaths addObject: indexPath];

}

if (indexPaths.count > 0) {

     [self.dataSource addObjectsFromArray:model.mediumArr];

     [self.collectionView insertItemsAtIndexPaths:indexPaths];

     [UIView performWithoutAnimation:^{

           [self.collectionView reloadItemsAtIndexPaths:indexPaths];

     }];

}


2.如果项目涉及到collectionView的滑动优化,在需要只调用reloadData的时候:添加如下动画。


[UIView animateWithDuration:0 animations:^{

      [self.collectionView performBatchUpdates:^{

            [self.collectionView reloadData];

       } completion: nil];

}];

你可能感兴趣的:(collectionView reloadData 引起闪屏)