diff --git a/SDWebImage/SDWebImageIndicator.h b/SDWebImage/SDWebImageIndicator.h index 845d3e6f..4078ab95 100644 --- a/SDWebImage/SDWebImageIndicator.h +++ b/SDWebImage/SDWebImageIndicator.h @@ -42,7 +42,7 @@ @param progress The progress, value between 0 and 1.0 */ -- (void)updateProgress:(double)progress; +- (void)updateIndicatorProgress:(double)progress; @end diff --git a/SDWebImage/SDWebImageIndicator.m b/SDWebImage/SDWebImageIndicator.m index 81115228..9aa06b56 100644 --- a/SDWebImage/SDWebImageIndicator.m +++ b/SDWebImage/SDWebImageIndicator.m @@ -174,7 +174,11 @@ - (void)startAnimatingIndicator { self.indicatorView.hidden = NO; #if SD_UIKIT - self.indicatorView.progress = 0; + if ([self.indicatorView respondsToSelector:@selector(observedProgress)] && self.indicatorView.observedProgress) { + // Ignore NSProgress + } else { + self.indicatorView.progress = 0; + } #else self.indicatorView.indeterminate = YES; self.indicatorView.doubleValue = 0; @@ -185,7 +189,11 @@ - (void)stopAnimatingIndicator { self.indicatorView.hidden = YES; #if SD_UIKIT - self.indicatorView.progress = 1; + if ([self.indicatorView respondsToSelector:@selector(observedProgress)] && self.indicatorView.observedProgress) { + // Ignore NSProgress + } else { + self.indicatorView.progress = 1; + } #else self.indicatorView.indeterminate = NO; self.indicatorView.doubleValue = 1; @@ -193,9 +201,13 @@ #endif } -- (void)updateProgress:(double)progress { +- (void)updateIndicatorProgress:(double)progress { #if SD_UIKIT - [self.indicatorView setProgress:progress animated:YES]; + if ([self.indicatorView respondsToSelector:@selector(observedProgress)] && self.indicatorView.observedProgress) { + // Ignore NSProgress + } else { + [self.indicatorView setProgress:progress animated:YES]; + } #else self.indicatorView.indeterminate = progress > 0 ? NO : YES; self.indicatorView.doubleValue = progress * 100; diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index 9c43b3d1..f929d7ff 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -73,13 +73,13 @@ static char imageURLKey; } if (url) { - // check and start image indicator - [self sd_startImageIndicator]; - // reset the progress self.sd_imageProgress.totalUnitCount = 0; self.sd_imageProgress.completedUnitCount = 0; + // check and start image indicator + [self sd_startImageIndicator]; + SDWebImageManager *manager; if ([context valueForKey:SDWebImageContextCustomManager]) { manager = (SDWebImageManager *)[context valueForKey:SDWebImageContextCustomManager]; @@ -99,22 +99,24 @@ static char imageURLKey; if ([imageIndicator conformsToProtocol:@protocol(SDWebImageProgressIndicator)]) { double progress = wself.sd_imageProgress.fractionCompleted; dispatch_async(dispatch_get_main_queue(), ^{ - [((id)imageIndicator) updateProgress:progress]; + [((id)imageIndicator) updateIndicatorProgress:progress]; }); } }; id operation = [manager loadImageWithURL:url options:options progress:combinedProgressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { __strong __typeof (wself) sself = wself; if (!sself) { return; } - // check and stop image indicator - if (finished) { - [self sd_stopImageIndicator]; - } // if the progress not been updated, mark it to complete state if (finished && !error && sself.sd_imageProgress.totalUnitCount == 0 && sself.sd_imageProgress.completedUnitCount == 0) { sself.sd_imageProgress.totalUnitCount = SDWebImageProgressUnitCountUnknown; sself.sd_imageProgress.completedUnitCount = SDWebImageProgressUnitCountUnknown; } + + // check and stop image indicator + if (finished) { + [self sd_stopImageIndicator]; + } + BOOL shouldCallCompletedBlock = finished || (options & SDWebImageAvoidAutoSetImage); BOOL shouldNotSetImage = ((image && (options & SDWebImageAvoidAutoSetImage)) || (!image && !(options & SDWebImageDelayPlaceholder)));