Просмотр исходного кода

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

Bogdan Poplauschi 9 лет назад
Родитель
Сommit
44cb993ee9

+ 14 - 14
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;
+                                 }];
     }
 }
 

+ 3 - 3
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;
 }
 

+ 8 - 8
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

+ 17 - 17
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"];
 }