我正在尝试创建一个函数作为 UIImageView 的扩展,使用 PinRemoteImage 逐步加载非渐进式图像。传递给函数的 URL 提供了一个渐进式 PNG 图像,即使 self.pin_updateWithProgress 选项为 true,它似乎也无法渐进式加载。
我更改了服务器的实现,以便在将 /128 添加到图像 URL 的末尾时服务器返回低分辨率图像。
然后我尝试首先将低分辨率图像(“/128”)加载到 UIImageView 中,然后使用另一个 pin_setImage 将最终高分辨率图像加载到 UIImageView,使用低分辨率图像作为 placeHolder。
代码如下所示:
func setProgressively(url: URL, completion: @escaping (Bool) -> Void) {
guard let url128 = URL(string: "\(url.absoluteString)/128") else { return }
self.pin_setImage(from: url128) { [weak self] (result) in
self?.clear()
self?.pin_setImage(from: url, placeholderImage: result.image, completion: { [weak self] (finalresult) in
PINRemoteImageManager.shared().cache.removeObject(forKey: PINRemoteImageManager.shared().cacheKey(for: url128, processorKey: nil))
self?.pin_updateUI(with: finalresult)
})
completion(true)
}
}
func clear() {
pin_cancelImageDownload()
pin_clearImages()
}
但是,UIImageView 不会从低分辨率图像更新,或者在某些情况下只加载高分辨率图像。
有没有人尝试过类似的实现并知道更好的做法?