【问题标题】:Objective C uiCollectionView scroll and load image make it feel lagObjective C uiCollectionView 滚动和加载图像让它感觉滞后
【发布时间】:2015-12-30 03:16:23
【问题描述】:

我必须将许多图像加载到UICollectionView。当我滚动UICollectionView 时,我觉得滚动到下一页时有点滞后。是因为我在进入下一页时加载了 12 张图片吗?如果是,我该如何解决。下面是我的代码。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *identifier = @"TestAZCollectionViewCell";

    TestAZCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    imgPath = [imgDir stringByAppendingPathComponent:[[itemArray objectAtIndex:indexPath.row]objectForKey:@"IM_ImgName"]];

    cell.cellImage.image = [UIImage imageWithContentsOfFile:imgPath];
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"no_image.jpg"]];


    return cell;
}

有人可以帮忙吗?

【问题讨论】:

标签: objective-c uicollectionview


【解决方案1】:

它滞后是因为系统需要从磁盘或网络加载图像-> 这里的慢点。要提高速度,您可以执行以下操作:

  • 使用不同的线程而不是主线程来加载图像对象,完成后 -> 通过主线程更新 UI。

  • 大尺寸的图片会导致 UI 滚动和加载时间变慢 -> 如果可能的话,将图片大小调整为集合中图片视图的大小。

  • 延迟加载,先显示带有图片持有者的单元格,加载完成后更新图片

【讨论】:

    【解决方案2】:

    试试这个方法:

    -(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath;

    或者找到一些新方法:

    UICollectionViewDelegate

    UICollectionViewDataSource


    希望能帮到你!

    【讨论】:

      【解决方案3】:

      我终于解决了这个问题。为了使其平滑滚动,我使用“haneke”来显示本地图像。希望可以帮助其他人

      【讨论】:

        猜你喜欢
        • 2017-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-03
        • 1970-01-01
        • 1970-01-01
        • 2019-03-31
        • 1970-01-01
        相关资源
        最近更新 更多