计算MBProgressHUD下载进度
Calculate MBProgressHUD download progress
我正在尝试计算下载进度,所以进度条开始移动,直到图像完全下载然后消失,但它一直显示,甚至没有移动进度指示器。我正在使用 SDWebimage progress 来获取 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)
我还收到以下错误:
<Error>: void CGPathAddArc(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool): invalid value for start or end angle.
完成后的值是:
progress:32477.0
我可以使用以下代码获得预期的输出:
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)
希望这能给你一个开始。
我正在尝试计算下载进度,所以进度条开始移动,直到图像完全下载然后消失,但它一直显示,甚至没有移动进度指示器。我正在使用 SDWebimage progress 来获取 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)
我还收到以下错误:
<Error>: void CGPathAddArc(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool): invalid value for start or end angle.
完成后的值是:
progress:32477.0
我可以使用以下代码获得预期的输出:
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)
希望这能给你一个开始。