Performance - UICollectionView Loading time very slow

狂风中的少年 提交于 2019-12-25 02:48:10

问题


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.

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.

My thoughts are:

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.

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?

Thanks!


回答1:


Check this sample code and try to get some idea from it https://developer.apple.com/library/ios/samplecode/lazytableimages/introduction/intro.html




回答2:


Try this

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];
    });
});


来源:https://stackoverflow.com/questions/22631394/performance-uicollectionview-loading-time-very-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!