PinRemoteImage - 完成一张图片下载后,将另一张图片加载到 UIImageView

时间:2021-06-18 03:28:09

标签: ios swift uiimageview progressive-download

我正在尝试创建一个函数作为 UIImageView 的扩展,它使用 PinRemoteImage 逐步加载非渐进式图像。 传递给函数的 URL 提供了一个渐进式 PNG 图像,即使 self.pin_updateWithProgress 选项为真,它似乎也无法渐进加载。

我更改了服务器的实现,以便在将 /128 添加到图像 URL 末尾时服务器返回低分辨率图像。

然后我尝试首先将低分辨率图像(“/128”)加载到 UIImageView 中,然后是另一个 pin_setImage 将最终高分辨率图像加载到 UIImageView,使用低分辨率图像作为 placeHolder。< /p>

代码如下所示:

    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 不会从低分辨率图像更新,或者它仅在某些情况下加载高分辨率图像。

有没有人尝试过类似的实现并知道更好的做法?

0 个答案:

没有答案