计算MBProgressHUD下载进度

时间:2015-08-21 11:02:56

标签: ios swift sdwebimage mbprogresshud

我试图计算下载进度,因此条形图开始移动直到图像完全下载然后消失,但它继续显示,甚至没有移动进度指示器。我正在使用SDWebimage进展来获得进步的价值。

let url = NSURL(string: (array[indexPath.row][0] as? String)!)
cell.imageView.sd_setImageWithURL(url, placeholderImage: nil, options: nil, progress: { (value1, value2) -> Void in

    dispatch_async(dispatch_get_main_queue(), {

    self.HUD = MBProgressHUD(view: self.mycollectionView)
    self.view.addSubview(self.HUD)

    self.HUD.mode = MBProgressHUDMode.AnnularDeterminate
    self.HUD.delegate = self
    self.HUD.show(true)
    var x : Float = Float(value1)
    self.HUD.progress = x
        var progress : Float = 0
        while (progress < x){
            progress += 0.1
            self.HUD.progress = progress
        }

      })

    }, completed: block)

此外,我收到以下错误:

<Error>: void CGPathAddArc(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool): invalid value for start or end angle.

当完成进度时,值就会出现:

progress:32477.0

1 个答案:

答案 0 :(得分:4)

我可以使用以下代码获得您的预期输出:

var HUD = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
HUD.mode = MBProgressHUDModeAnnularDeterminate

let url = NSURL(string: "urlString")
imageView.sd_setImageWithPreviousCachedImageWithURL(url, andPlaceholderImage: nil, options: nil, progress: { (value1, value2) -> Void in
       var progress = Float(value1)/Float(value2)
       HUD.progress = progress
}, completed: nil)

希望这能给你一个开始。