【发布时间】:2016-12-30 09:10:06
【问题描述】:
我正在使用 SDWebImage 库在集合视图中加载图像。
库从服务器和缓存下载图像,但是当我退出我的应用程序并重新运行时,从缓存加载图像需要时间。 (占位符图像显示 2-3 秒有时甚至更长)
使用 SDWebImage 加载图像的代码:
cell.imgPost.sd_setImage(with: URL(string: (post.lowQualityImgUrl) ?? ""), placeholderImage: UIImage(named:"greybg") , options: .refreshCached, progress: { (recievedSize, expectedSize) in
progressIndicatorView.progress = CGFloat(recievedSize)/CGFloat(expectedSize)
}, completed: { (image, error, cachetype, url) in
if image != nil{
DispatchQueue.main.async {
progresView.removeFromSuperview()
progressIndicatorView.removeFromSuperview()
cell.progressIndicatorView?.isHidden = true
cell.imgPost.image = image
}
}
})
这里使用的缓存选项是刷新缓存。
问题: 我不知道为什么集合视图单元格不能使用 sdwebimage 立即加载图像。正如它所说 sdwebimage 是图像缓存的最佳库。 谁能指出解决方案/问题?
编辑 我确实在他们的图书馆留下了评论,我认为这从来都不是一个好的图书馆。 https://github.com/rs/SDWebImage/issues/138
提前致谢。
【问题讨论】:
-
为什么要在块内使用
cell.imgPost.image = image再次设置图像。?它已经被这个cell.imgPost.sd_setImage(with:块设置了。 -
@Poles 如果我不放置 cell.imgpost.image = image 然后在滚动图像视图上再次显示占位符我不知道我错过了什么
标签: ios swift uicollectionview sdwebimage image-caching