From 44cb993ee9af59aad1b282c5fa414aac511cd265 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Wed, 1 Jun 2016 10:11:46 +0300 Subject: [PATCH] Successfull attempt to override the UIImageView(WebCache) methods in the FLAnimatedImageView(WebCache) category. This should make the integration easier. Not sure if it will always work --- .../SDWebImage Demo/DetailViewController.m | 28 +++++++-------- .../SDWebImage Demo/MasterViewController.m | 6 ++-- .../FLAnimatedImageView+WebCache.h | 16 ++++----- .../FLAnimatedImageView+WebCache.m | 34 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Examples/SDWebImage Demo/DetailViewController.m b/Examples/SDWebImage Demo/DetailViewController.m index ef483bd..da57ed7 100644 --- a/Examples/SDWebImage Demo/DetailViewController.m +++ b/Examples/SDWebImage Demo/DetailViewController.m @@ -39,20 +39,20 @@ if (self.imageURL) { __block UIActivityIndicatorView *activityIndicator; __weak UIImageView *weakImageView = self.imageView; - [self.imageView sd_setAnimatedImageWithURL:self.imageURL - placeholderImage:nil - options:SDWebImageProgressiveDownload - progress:^(NSInteger receivedSize, NSInteger expectedSize) { - 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]; - activityIndicator = nil; - }]; + [self.imageView sd_setImageWithURL:self.imageURL + placeholderImage:nil + options:SDWebImageProgressiveDownload + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + 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]; + activityIndicator = nil; + }]; } } diff --git a/Examples/SDWebImage Demo/MasterViewController.m b/Examples/SDWebImage Demo/MasterViewController.m index 1addc8e..4e580cc 100644 --- a/Examples/SDWebImage Demo/MasterViewController.m +++ b/Examples/SDWebImage Demo/MasterViewController.m @@ -124,9 +124,9 @@ [cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray]; cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; - [cell.customImageView sd_setAnimatedImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] - placeholderImage:placeholderImage - options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; + [cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] + placeholderImage:placeholderImage + options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; return cell; } diff --git a/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h b/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h index dfccad6..b0b31f0 100644 --- a/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h +++ b/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h @@ -36,7 +36,7 @@ * * @param url The url for the image. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url; +- (void)sd_setImageWithURL:(NSURL *)url; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -46,7 +46,7 @@ * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -57,7 +57,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -70,7 +70,7 @@ * indicating if the image was retrieved from the local cache or from the network. * The fourth parameter is the original image url. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -85,7 +85,7 @@ * indicating if the image was retrieved from the local cache or from the network. * The fourth parameter is the original image url. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -101,7 +101,7 @@ * indicating if the image was retrieved from the local cache or from the network. * The fourth parameter is the original image url. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock; /** * Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images @@ -118,11 +118,11 @@ * indicating if the image was retrieved from the local cache or from the network. * The fourth parameter is the original image url. */ -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock; /** * Cancel the image load */ -- (void)sd_cancelCurrentAnimatedImageLoad; +- (void)sd_cancelCurrentImageLoad; @end diff --git a/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m b/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m index 3b90f05..9c436e5 100644 --- a/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m +++ b/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m @@ -23,32 +23,32 @@ static char imageURLKey; return objc_getAssociatedObject(self, &imageURLKey); } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url { - [self sd_setAnimatedImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock { - [self sd_setAnimatedImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock { - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock { - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; } -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock { - [self sd_cancelCurrentAnimatedImageLoad]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock { + [self sd_cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); if (!(options & SDWebImageDelayPlaceholder)) { @@ -94,7 +94,7 @@ static char imageURLKey; } }); }]; - [self sd_setImageLoadOperation:operation forKey:@"UIImageViewAnimatedImageLoad"]; + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; } else { dispatch_main_async_safe(^{ [self removeActivityIndicator]; @@ -107,8 +107,8 @@ static char imageURLKey; } } -- (void)sd_cancelCurrentAnimatedImageLoad { - [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimatedImageLoad"]; +- (void)sd_cancelCurrentImageLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; }