From 5d2963ac73d5fc823abda5d3a8785e04c11372b7 Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Thu, 18 Jun 2015 19:18:45 +0200 Subject: [PATCH 1/2] Add an option called "SDWebImageAvoidAutoImageFill" to avoid automatic image addition in UIImageView and let developer to do it himself --- SDWebImage/SDWebImageManager.h | 7 +++++++ SDWebImage/UIImageView+WebCache.m | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index ec682ba8..1b8b7e18 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -82,6 +82,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { * Use this flag to transform them anyway. */ SDWebImageTransformAnimatedImage = 1 << 10, + + /** + * By default, image is added to the imageView after download. But in some cases, we want to + * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) + * Use this flag if you want to manually set the image in the completion when success + */ + SDWebImageAvoidAutoImageFill = 1 << 11 }; typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 945246f5..7b78dad5 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -54,7 +54,12 @@ static char imageURLKey; if (!wself) return; dispatch_main_sync_safe(^{ if (!wself) return; - if (image) { + if (image && (options & SDWebImageAvoidAutoImageFill) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { wself.image = image; [wself setNeedsLayout]; } else { From 4d6693c81339b452e3edb611cbbe42593d7c838a Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Wed, 1 Jul 2015 10:11:35 +0200 Subject: [PATCH 2/2] Rename SDWebImageAvoidAutoImageFill option to SDWebImageAvoidAutoSetImage --- SDWebImage/SDWebImageManager.h | 2 +- SDWebImage/UIImageView+WebCache.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 1b8b7e18..7f80e242 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -88,7 +88,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) * Use this flag if you want to manually set the image in the completion when success */ - SDWebImageAvoidAutoImageFill = 1 << 11 + SDWebImageAvoidAutoSetImage = 1 << 11 }; typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 7b78dad5..162c49af 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -54,7 +54,7 @@ static char imageURLKey; if (!wself) return; dispatch_main_sync_safe(^{ if (!wself) return; - if (image && (options & SDWebImageAvoidAutoImageFill) && completedBlock) + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) { completedBlock(image, error, cacheType, url); return;