我们有一些所谓intervention,我们有我们的后端。它为我们提供了我们可以通过URL
后卫让后提供的宽度和高度缩放图像的URL网址= IMAGEURL其他{返回}
VAR smallURL = URL + “/” +“ (20)” +‘/’+‘(20)’
所以,我在这里做的是,我加载具有尺寸(20×20)的图像第一并显示为模糊的图像,并且当与实际图像大小已加载我将其替换为原始图像。
这样,它是一个很好的用户体验,因为用户不必等待图像加载,而是获得图像加载的印象。
,这些东西在图像视图的扩展这样做,你可以直接称呼其为:
imageView.setImage(IMAGEURL: “https://i.stack.imgur.com/GsDIl.jpg”)
extension UIImageView {
func setImage(imageURL : String?,size : CGFloat = ScreenSize.width){
guard let url = imageURL else { return }
var originalURL = url
var smallURL = url + "/" + "\(20)" + "/" + "\(20)"
let actualImageUrl = URL(string: name)
let smallURL = URL(string: smallName)
self.backgroundColor = UIColor.lightGray.withAlphaComponent(0.5)
self.yy_setImage(with: smallURL, placeholder: nil, options: .showNetworkActivity) { (image, _, _, _, _) in
guard let _ = image else { return }
let blurredImg = image?.applyBlurWithRadius(0.5, tintColor: UIColor.black.withAlphaComponent(0.4), saturationDeltaFactor: 1.0)
self.image = blurredImg
self.yy_setImage(with: actualImageUrl, placeholder: blurredImg, options: .progressiveBlur, completion: { [weak self] (image, url, type, _, _) in
self?.image = image
})
}
}
}
相反使用SDWebImage我已经使用YYWebImage它提供了更多的功能,它基于SDWebImage。
希望它有助于!
你在不同的网络中测试过吗? – user3581248
你可以做的不多。如果图像大小为12MB,即使下载速度为1MB /秒,也需要12秒才能下载图像。 – jokeman
@jokeman感谢您的回复。这些是我从iPhone 6上传的图像,所以没有什么不同寻常的 – JK140