我有一个模拟封面流的集合视图。它像这样从 ALAssetLibrary 异步加载图像。
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
myCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CELL_ID" forIndexPath:indexPath];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
ALAsset *asset = [assets objectAtIndex:indexPath.row];
CGImageRef thumbnailImageRef = [[asset defaultRepresentation]fullScreenImage];
UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef];
dispatch_async(dispatch_get_main_queue(), ^{
cell.myImageView.image = thumbnail;
});
});
return cell;
}
如果用户快速滚动,则加载图像需要更长的时间。我在想,如果用户快速滚动到图像 20,他们必须等待图像 1-19 加载,即使它们不再在屏幕上。所以,我的问题是,如果单元格在加载过程完成之前移出屏幕,有没有办法停止图像加载?