SDWebImage使用MBProgress进度条问题

SDWebImage progress中使用MBProgress进度条必须回到主线程才能刷新进度,否则进度条不会动。

代码:

//已经封装好的MBProgressHUDProgress
_HUD = [Tools MBProgressHUDProgress:@"Loading"];
_HUD.progress = 0;   
//SDWebImage加载图片
[_imageView sd_setImageWithURL:wallpaper.fullSize placeholderImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:wallpaper.thumbnail]] options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
    //加载进度
    float progress = (float)receivedSize/expectedSize;
    NSLog(@"下载进度:%f",progress);
    dispatch_sync(dispatch_get_main_queue() , ^{
        //必须返回主线程才能刷新UI
        _HUD.progress = progress;
    });
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
    [_HUD hideAnimated:YES];
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"没找到高清图" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
        [alertView show];
    }else{
 self.navigationItem.rightBarButtonItem.enabled = YES;
        }
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容