1、使用runloop的小操作
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PlaysListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"itemcell" forIndexPath:indexPath];
/**
runloop - 滚动时候 - trackingMode,
- 默认情况 - defaultRunLoopMode
==> 滚动的时候,进入`trackingMode`,defaultMode下的任务会暂停
停止滚动的时候 - 进入`defaultMode` - 继续执行`trackingMode`下的任务
*/
[self performSelector:@selector(p_loadImgeWithIndexPath:)
withObject:indexPath
afterDelay:0.0
inModes:@[NSDefaultRunLoopMode]];
return cell;
}
2、使用ScrollView的代理 判断当前是否在滑动中
//核心判断:tableView非滚动状态下,才进行图片下载并渲染
- (void)p_loadImage{
//拿到界面内-所有的cell的indexpath
NSArray *visableCellIndexPaths = self.collectionView.indexPathsForVisibleItems;
for (NSIndexPath *indexPath in visableCellIndexPaths) {
PlaysHomeListModel *model = self.datasource[indexPath.row];
PlaysListCollectionViewCell *cell = (PlaysListCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
[cell configViewWithModel:model];
}
}
//手一直在拖拽控件
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[self p_loadImage];
}
//手放开了-使用惯性-产生的动画效果
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if(!decelerate){
//直接停止-无动画
[self p_loadImage];
}else{
//有惯性的-会走`scrollViewDidEndDecelerating`方法,这里不用设置
}
}