UIcollectionView具有缓慢的图像加载和滚动

use*_*733 0 performance xcode uiimage uicollectionview

我有一个UICollectionView,里面有一些图像.在第一次向下滚动时加载图像非常慢且不稳定.之后,当图像加载时,它很好.

我想问题是图像不会被加载,直到单元格到达屏幕导致滞后.我假设我需要做的是在图像出现在屏幕上之前加载图像.我不知道该怎么做,显然是在寻找错误的东西,因为我找不到任何答案.请有人指出我正确的方向吗?

这是加载图像的代码......图像在我的应用程序中没有下载或任何东西.

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    [[cell myImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

its*_*dra 5

看看这个答案

出列后添加这两行

cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
Run Code Online (Sandbox Code Playgroud)