Successfull attempt to override the UIImageView(WebCache) methods in the FLAnima…
…tedImageView(WebCache) category. This should make the integration easier. Not sure if it will always work
Showing
4 changed files
with
42 additions
and
42 deletions
@@ -39,20 +39,20 @@ | @@ -39,20 +39,20 @@ | ||
39 | if (self.imageURL) { | 39 | if (self.imageURL) { |
40 | __block UIActivityIndicatorView *activityIndicator; | 40 | __block UIActivityIndicatorView *activityIndicator; |
41 | __weak UIImageView *weakImageView = self.imageView; | 41 | __weak UIImageView *weakImageView = self.imageView; |
42 | - [self.imageView sd_setAnimatedImageWithURL:self.imageURL | ||
43 | - placeholderImage:nil | ||
44 | - options:SDWebImageProgressiveDownload | ||
45 | - progress:^(NSInteger receivedSize, NSInteger expectedSize) { | ||
46 | - if (!activityIndicator) { | ||
47 | - [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]]; | ||
48 | - activityIndicator.center = weakImageView.center; | ||
49 | - [activityIndicator startAnimating]; | ||
50 | - } | ||
51 | - } | ||
52 | - completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { | ||
53 | - [activityIndicator removeFromSuperview]; | ||
54 | - activityIndicator = nil; | ||
55 | - }]; | 42 | + [self.imageView sd_setImageWithURL:self.imageURL |
43 | + placeholderImage:nil | ||
44 | + options:SDWebImageProgressiveDownload | ||
45 | + progress:^(NSInteger receivedSize, NSInteger expectedSize) { | ||
46 | + if (!activityIndicator) { | ||
47 | + [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]]; | ||
48 | + activityIndicator.center = weakImageView.center; | ||
49 | + [activityIndicator startAnimating]; | ||
50 | + } | ||
51 | + } | ||
52 | + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { | ||
53 | + [activityIndicator removeFromSuperview]; | ||
54 | + activityIndicator = nil; | ||
55 | + }]; | ||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 |
@@ -124,9 +124,9 @@ | @@ -124,9 +124,9 @@ | ||
124 | [cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray]; | 124 | [cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray]; |
125 | 125 | ||
126 | cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; | 126 | cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; |
127 | - [cell.customImageView sd_setAnimatedImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] | ||
128 | - placeholderImage:placeholderImage | ||
129 | - options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; | 127 | + [cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] |
128 | + placeholderImage:placeholderImage | ||
129 | + options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; | ||
130 | return cell; | 130 | return cell; |
131 | } | 131 | } |
132 | 132 |
@@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
36 | * | 36 | * |
37 | * @param url The url for the image. | 37 | * @param url The url for the image. |
38 | */ | 38 | */ |
39 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url; | 39 | +- (void)sd_setImageWithURL:(NSURL *)url; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * 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 | 42 | * 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 @@ | @@ -46,7 +46,7 @@ | ||
46 | * @param url The url for the image. | 46 | * @param url The url for the image. |
47 | * @param placeholder The image to be set initially, until the image request finishes. | 47 | * @param placeholder The image to be set initially, until the image request finishes. |
48 | */ | 48 | */ |
49 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; | 49 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * 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 | 52 | * 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 @@ | @@ -57,7 +57,7 @@ | ||
57 | * @param placeholder The image to be set initially, until the image request finishes. | 57 | * @param placeholder The image to be set initially, until the image request finishes. |
58 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. | 58 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. |
59 | */ | 59 | */ |
60 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; | 60 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * 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 | 63 | * 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 @@ | @@ -70,7 +70,7 @@ | ||
70 | * indicating if the image was retrieved from the local cache or from the network. | 70 | * indicating if the image was retrieved from the local cache or from the network. |
71 | * The fourth parameter is the original image url. | 71 | * The fourth parameter is the original image url. |
72 | */ | 72 | */ |
73 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock; | 73 | +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * 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 | 76 | * 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 @@ | @@ -85,7 +85,7 @@ | ||
85 | * indicating if the image was retrieved from the local cache or from the network. | 85 | * indicating if the image was retrieved from the local cache or from the network. |
86 | * The fourth parameter is the original image url. | 86 | * The fourth parameter is the original image url. |
87 | */ | 87 | */ |
88 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock; | 88 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * 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 | 91 | * 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 @@ | @@ -101,7 +101,7 @@ | ||
101 | * indicating if the image was retrieved from the local cache or from the network. | 101 | * indicating if the image was retrieved from the local cache or from the network. |
102 | * The fourth parameter is the original image url. | 102 | * The fourth parameter is the original image url. |
103 | */ | 103 | */ |
104 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock; | 104 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock; |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * 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 | 107 | * 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 @@ | @@ -118,11 +118,11 @@ | ||
118 | * indicating if the image was retrieved from the local cache or from the network. | 118 | * indicating if the image was retrieved from the local cache or from the network. |
119 | * The fourth parameter is the original image url. | 119 | * The fourth parameter is the original image url. |
120 | */ | 120 | */ |
121 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock; | 121 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Cancel the image load | 124 | * Cancel the image load |
125 | */ | 125 | */ |
126 | -- (void)sd_cancelCurrentAnimatedImageLoad; | 126 | +- (void)sd_cancelCurrentImageLoad; |
127 | 127 | ||
128 | @end | 128 | @end |
@@ -23,32 +23,32 @@ static char imageURLKey; | @@ -23,32 +23,32 @@ static char imageURLKey; | ||
23 | return objc_getAssociatedObject(self, &imageURLKey); | 23 | return objc_getAssociatedObject(self, &imageURLKey); |
24 | } | 24 | } |
25 | 25 | ||
26 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url { | ||
27 | - [self sd_setAnimatedImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; | 26 | +- (void)sd_setImageWithURL:(NSURL *)url { |
27 | + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; | ||
28 | } | 28 | } |
29 | 29 | ||
30 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { | ||
31 | - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; | 30 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { |
31 | + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; | ||
32 | } | 32 | } |
33 | 33 | ||
34 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { | ||
35 | - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; | 34 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { |
35 | + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; | ||
36 | } | 36 | } |
37 | 37 | ||
38 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock { | ||
39 | - [self sd_setAnimatedImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; | 38 | +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock { |
39 | + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; | ||
40 | } | 40 | } |
41 | 41 | ||
42 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock { | ||
43 | - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; | 42 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock { |
43 | + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; | ||
44 | } | 44 | } |
45 | 45 | ||
46 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock { | ||
47 | - [self sd_setAnimatedImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; | 46 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock { |
47 | + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; | ||
48 | } | 48 | } |
49 | 49 | ||
50 | -- (void)sd_setAnimatedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock { | ||
51 | - [self sd_cancelCurrentAnimatedImageLoad]; | 50 | +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock { |
51 | + [self sd_cancelCurrentImageLoad]; | ||
52 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | 52 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
53 | 53 | ||
54 | if (!(options & SDWebImageDelayPlaceholder)) { | 54 | if (!(options & SDWebImageDelayPlaceholder)) { |
@@ -94,7 +94,7 @@ static char imageURLKey; | @@ -94,7 +94,7 @@ static char imageURLKey; | ||
94 | } | 94 | } |
95 | }); | 95 | }); |
96 | }]; | 96 | }]; |
97 | - [self sd_setImageLoadOperation:operation forKey:@"UIImageViewAnimatedImageLoad"]; | 97 | + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; |
98 | } else { | 98 | } else { |
99 | dispatch_main_async_safe(^{ | 99 | dispatch_main_async_safe(^{ |
100 | [self removeActivityIndicator]; | 100 | [self removeActivityIndicator]; |
@@ -107,8 +107,8 @@ static char imageURLKey; | @@ -107,8 +107,8 @@ static char imageURLKey; | ||
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | -- (void)sd_cancelCurrentAnimatedImageLoad { | ||
111 | - [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimatedImageLoad"]; | 110 | +- (void)sd_cancelCurrentImageLoad { |
111 | + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; | ||
112 | } | 112 | } |
113 | 113 | ||
114 | 114 |
-
Please register or login to post a comment