The docs say the progressBlock is called on a background queue, so when doing UI, we need to dispatch on the main queue

* @param progressBlock  A block called while image is downloading
* @note the progress block is executed on a background queue
This commit is contained in:
Bogdan Poplauschi 2017-08-11 16:38:32 +03:00
parent ecdd0128ab
commit 7b79c29a8c
1 changed files with 7 additions and 5 deletions

View File

@ -43,11 +43,13 @@
placeholderImage:nil
options:SDWebImageProgressiveDownload
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
if (!activityIndicator) {
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (!activityIndicator) {
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
});
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[activityIndicator removeFromSuperview];