SDWebImage不从url分配图像 - 下载的图像有0像素

时间:2016-02-12 18:57:25

标签: ios swift uiimageview sdwebimage

这是UIImageView的简单扩展名:

extension UIImageView {

func setImageWithUrl(url: String?) {
    setImageWithUrl(url, placeholder: nil)
}

private func setImageWithUrl(url: String?, placeholder: UIImage? = UIImage(), deleteCacheImage: Bool = false) {

    image = placeholder ?? image

    if let url = url {

        let activityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)))
        activityIndicatorView.hidden = false
        activityIndicatorView.color = UIColor.curiousBlue()

        addSubview(activityIndicatorView)
        bringSubviewToFront(activityIndicatorView)

        activityIndicatorView.startAnimating()

        let options = deleteCacheImage ? SDWebImageOptions.RefreshCached : SDWebImageOptions.LowPriority

        sd_setImageWithURL(NSURL(string: url), placeholderImage: placeholder, options: options, completed: { image, error, cache, url in

            activityIndicatorView.hidden = true
            activityIndicatorView.stopAnimating()
            activityIndicatorView.removeFromSuperview()
        })
    }
}
}

示例image

但块中的imagenil。为什么?它返回一个错误:

  

下载的图片有0像素

我有SDWebImage的最新版本,通过cocoapods: 3.7.5

0 个答案:

没有答案