解决方案:使用网络缓存的图片
// import YYWebImage
// MARK: 设置网络图片
func c_webImage(_ url: String, _ placeholder: String = "EXAssets40") {
if let image = YYWebImageManager.shared().cache?.getImageForKey(url) {
self.image = image
} else {
if let imgUrl = URL.init(string: url) {
YYWebImageManager.shared().requestImage(with: imgUrl,
options: .useNSURLCache,
progress: nil,
transform: nil){[weak self] (image, url , type, stage, err) in
guard let `self` = self else {return}
DispatchQueue.main.async(execute: {
if let downloadedImg = image {
self.image = downloadedImg
} else {
self.image = UIImage.init(named: placeholder)
}
})
}
} else {
self.image = CTools.getImage(placeholder)
}
}
}