【发布时间】:2014-10-03 20:53:13
【问题描述】:
我有一个UICollectionView,它可以加载 iPad 内存的图像并将它们显示在网格中,就像 Apple 的照片应用程序一样。 UICollectionViewCell 异步加载缩略图:
func setImage(img:String){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//load the image in the background
let image = UIImage(contentsOfFile: img)
//when done, assign it to the cell's UIImageView
dispatch_async(dispatch_get_main_queue(), {
if let imageView = self.imageView{
imageView.image = UIImage(contentsOfFile: img)
}
})
})
}
但是,在滚动视图时,它就像在等待图像加载一样滞后,尤其是在使用 Retina 图形时。单元格和图像大约为 240x180px 大。上面的图片加载有什么问题还是需要进一步优化?
更新:时间分析器结果
【问题讨论】:
-
将线程的优先级从 DISPATCH_QUEUE_PRIORITY_DEFAULT 更改为 DISPATCH_QUEUE_PRIORITY_BACKGROUND 或 DISPATCH_QUEUE_PRIORITY_LOW,看看您的收藏视图是否表现更好
-
我试过了,不行。
标签: ios asynchronous swift uiimage uicollectionview