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

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容