【问题标题】:Placeholder image as Thumbnail(blurred) until actual image loads占位符图像为缩略图(模糊),直到实际图像加载
【发布时间】:2018-12-07 01:40:47
【问题描述】:

我有下面的代码,一旦用户选择它就会显示全屏图像。

fullImage.kf.setImage(with: url)

在实际图像下载期间,我想将占位符显示为相同的图像,但缩略图尺寸被拉长。此缩略图在之前显示缩略图时被 Kingfisher 库缓存。

当我在没有 KF 库的情况下显示图像时,通过使用常规 iOS UIImage 下载器,它会显示拉伸缩略图的模糊预览,然后显示实际图像。使用 KF 库如何实现这一点?

【问题讨论】:

  • 为什么被否决???

标签: swift placeholder blur kingfisher


【解决方案1】:

您可以使用如下所示的占位符图片

fullImage.kf.setImage(with: url, placeholder: UIImage(named: "placeholder"), options: nil, progressBlock: nil, completionHandler: nil)

但要显示缩略图,您必须单独下载缩略图。

【讨论】:

    【解决方案2】:

    如果您希望缩略图成为网络上的图像,您可以按照人们的建议进行操作 on GitHub

    let cacheImage = ImageCache.default.retrieveImageInDiskCache(forKey: "cache")
    
    let resource = ImageResource(downloadURL: imageURL, cacheKey: "cache")
    
    imageView.kf.setImage(with: resource, placeholder: cacheImage, options: [.keepCurrentImageWhileLoading], progressBlock: nil, completionHandler: nil)
    

    不过,您需要先找到一种下载缩略图的方法,这可以通过多种方式完成,例如使用ImagePrefetcher

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 2020-10-24
      • 1970-01-01
      • 2013-04-29
      相关资源
      最近更新 更多