进度的Block在子线程调用

[_pictureView sd_setImageWithURL:[NSURL URLWithString:item.image2] placeholderImage:nil options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {

    

    //        NSLog(@"%ld %ld",receivedSize,expectedSize);

    if (expectedSize == -1) return ;

    

    CGFloat progress = 1.0 * receivedSize / expectedSize;

    

    NSString *str = [NSString stringWithFormat:@"%.0f%%",progress * 100];

    

    dispatch_sync(dispatch_get_main_queue(), ^{

        _progressView.progressLabel.text = str;

        

        _progressView.progress = progress;

    });

    

} completed:nil];

 

完事皆项目,感兴趣可联系我邮箱~hjjuny@163.com
原文地址:https://www.cnblogs.com/hjjun/p/6001543.html