Scroll view and table view performance when loading images from disk

后端 未结 5 1669
说谎
说谎 2021-02-04 18:50

I\'m trying to improve the performance of my image-intensive iPhone app by using a disk-based image cache instead of going over the network. I\'ve modeled my image cache after S

5条回答
  •  没有蜡笔的小新
    2021-02-04 19:17

    It's typically the image decoding which takes time, and that causes the UI to freeze (since it's all happening on the main thread). Every time you call [UIImage imageWithData:] on a large image, you'll notice a hiccup. Decoding a smaller image is far quicker.

    Two options:

    1. You can load a thumbnail version of each image first, then 'sharpen up' on didFinishScrolling. The thumbnails should decode quickly enough such that you don't skip any frames.
    2. You can load a thumbnail version of each image or show a loading indicator first, then decode the full-resolution image on another thread, and sub it in when it's ready. (This is the technique that is employed in the native Photos app).

    I prefer the second approach; it's easy enough with GDC nowadays.

提交回复
热议问题