AaoIi AaoIi - 1 month ago 16
Swift Question

Calculate MBProgressHUD download progress

Im trying to calculate download progress, so the bar start moving until the image is fully downloaded and then disappear , but it keeps on showing without even moving the indicator of progress. I am using SDWebimage progress to get the value of progress.

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)


Also I'm getting the following error :

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


The values comes to be when done the progress is :

progress:32477.0

Answer

I am able to get your expected output using following code :

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)

Hope this give you a start.

Comments