Loading UIImage in background thread causes ImageIO error

前端 未结 1 1989
悲哀的现实
悲哀的现实 2021-02-06 19:29

I am working on an iOS project that loads UIImages from URLs in a background thread and displays them in a horizontally paged scroll view. This behavior should mimic that of the

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 20:25

    UIKit is not a thread-safe class. Therefore, you should not call UIImage from the background.

    Rather than create UIImages, render your images files into CGImageRefs. You can pass one of these back to the main thread and generate a UIImage from that (you will have still benefited by moving the heavy-lifting of image decompression to the background).

    0 讨论(0)
提交回复
热议问题