性能-UICollectionView加载时间非常慢 [英] Performance - UICollectionView Loading time very slow

查看:221
本文介绍了性能-UICollectionView加载时间非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用iDevice相机拍摄照片并将其作为PNG存储在文件系统上的应用程序.启动我的应用程序时,我将加载一个UICollectionView以及在文件系统上找到的图像.

I am writing an app that takes a picture using the iDevice camera and stores it on the file system as a PNG. When starting my app, I load a UICollectionView with the images found on the file system.

我面临的问题是该应用程序的加载时间(即使仅加载6张图像大约需要4秒,这也是无法接受的.我已经实现了GCD在后台线程上加载图像(这使UI保持活泼)但是,我真的希望应用程序在加载图像后能更快地启动.

The issue I am facing is that the load time for the app (even when its only loading 6 images is approximately 4 seconds which is unacceptable. I have implemented GCD to load images on a background thread (which keeps the UI snappy) however I really want the app to start far quicker with images loaded.

我的想法是:

我怀疑initWithContentsOfFile需要花费很多时间才能加载完整尺寸的图像. 我考虑过要在拍摄照片时生成一个单独的缩略图,然后加载该缩略图.

I suspect the initWithContentsOfFile is taking ages to load the full size image. I thought about generating a separate thumbnail image when a picture is taken and load that instead.

当我查看Apple的Photo应用程序时,它最终会立即"加载并显示10张图片.

Ultimately when I look at Apple's Photo app, it loads "instantly" and has 10's of pictures in view.

有人对我如何更快地加载图像或至少看起来看起来有什么建议吗?

Does anyone have any suggestions for how I can load the images faster or at least appear to?

谢谢!

推荐答案

尝试一下

在后台线程中加载图像并在主线程中设置

Load image in background thread and set in main thread

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

    UIImage *image = [UIImage imageWithContentsOfFile:frontPath];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.frontButton setBackgroundImage:image forState:UIControlStateNormal];
    });
});

这篇关于性能-UICollectionView加载时间非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆