美文网首页
SDWebImage使用MBProgress进度条问题

SDWebImage使用MBProgress进度条问题

作者: 聆默无语 | 来源:发表于2017-02-18 14:35 被阅读261次

    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;
            }
        }];
    

    相关文章

      网友评论

          本文标题:SDWebImage使用MBProgress进度条问题

          本文链接:https://www.haomeiwen.com/subject/hgvrwttx.html