Merge branch 'master' of git://github.com/gringoireDM/SDWebImage into gringoireDM-master

This commit is contained in:
Olivier Poitrey 2013-07-31 13:50:14 -07:00
commit 8b37b16f45
2 changed files with 69 additions and 0 deletions

View File

@ -134,9 +134,18 @@
*/
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
/**
* Download an array of images and starts them in an animation loop
*
*@param arrayOfURLs An array of NSURL
*/
-(void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
/**
* Cancel the current download
*/
- (void)cancelCurrentImageLoad;
- (void)cancelCurrentArrayLoad;
@end

View File

@ -10,6 +10,7 @@
#import "objc/runtime.h"
static char operationKey;
static char operationArrayKey;
@implementation UIImageView (WebCache)
@ -82,6 +83,51 @@ static char operationKey;
}
}
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs
{
[self cancelCurrentArrayLoad];
__weak UIImageView *wself = self;
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
for (NSURL *logoImageURL in arrayOfURLs)
{
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
if (!wself) return;
void (^block)(void) = ^
{
__strong UIImageView *sself = wself;
[sself stopAnimating];
if (sself && image)
{
NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
if (!currentImages)
{
currentImages = [[NSMutableArray alloc] init];
}
[currentImages addObject:image];
sself.animationImages = currentImages;
[sself setNeedsLayout];
}
[sself startAnimating];
};
if ([NSThread isMainThread])
{
block();
}
else
{
dispatch_sync(dispatch_get_main_queue(), block);
}
}];
[operationsArray addObject:operation];
}
objc_setAssociatedObject(self, &operationArrayKey, [NSArray arrayWithArray:operationsArray], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)cancelCurrentImageLoad
{
// Cancel in progress downloader from queue
@ -93,4 +139,18 @@ static char operationKey;
}
}
- (void)cancelCurrentArrayLoad
{
// Cancel in progress downloader from queue
NSArray *operations = objc_getAssociatedObject(self, &operationArrayKey);
for (id<SDWebImageOperation> operation in operations)
{
if (operation)
{
[operation cancel];
}
}
objc_setAssociatedObject(self, &operationArrayKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end