123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #import "UIImageView+WebCache.h"
- #if SD_UIKIT || SD_MAC
- #import "objc/runtime.h"
- #import "UIView+WebCacheOperation.h"
- #import "UIView+WebCache.h"
- @implementation UIImageView (WebCache)
- - (void)sd_setImageWithURL:(nullable NSURL *)url {
- [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder {
- [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
- [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
- [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
- [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock {
- [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
- }
- - (void)sd_setImageWithURL:(nullable NSURL *)url
- placeholderImage:(nullable UIImage *)placeholder
- options:(SDWebImageOptions)options
- progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
- completed:(nullable SDExternalCompletionBlock)completedBlock {
- [self sd_internalSetImageWithURL:url
- placeholderImage:placeholder
- options:options
- operationKey:nil
- setImageBlock:nil
- progress:progressBlock
- completed:completedBlock];
- }
- - (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url
- placeholderImage:(nullable UIImage *)placeholder
- options:(SDWebImageOptions)options
- progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
- completed:(nullable SDExternalCompletionBlock)completedBlock {
- NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
- UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
-
- [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
- }
- #if SD_UIKIT
- #pragma mark - Animation of multiple images
- - (void)sd_setAnimationImagesWithURLs:(nonnull NSArray<NSURL *> *)arrayOfURLs {
- [self sd_cancelCurrentAnimationImagesLoad];
- __weak __typeof(self)wself = self;
- NSMutableArray<id<SDWebImageOperation>> *operationsArray = [[NSMutableArray alloc] init];
- [arrayOfURLs enumerateObjectsUsingBlock:^(NSURL *logoImageURL, NSUInteger idx, BOOL * _Nonnull stop) {
- id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
- if (!wself) return;
- dispatch_main_async_safe(^{
- __strong UIImageView *sself = wself;
- [sself stopAnimating];
- if (sself && image) {
- NSMutableArray<UIImage *> *currentImages = [[sself animationImages] mutableCopy];
- if (!currentImages) {
- currentImages = [[NSMutableArray alloc] init];
- }
-
-
-
-
-
- while ([currentImages count] < idx) {
- [currentImages addObject:image];
- }
-
- currentImages[idx] = image;
- sself.animationImages = currentImages;
- [sself setNeedsLayout];
- }
- [sself startAnimating];
- });
- }];
- [operationsArray addObject:operation];
- }];
- [self sd_setImageLoadOperation:[operationsArray copy] forKey:@"UIImageViewAnimationImages"];
- }
- - (void)sd_cancelCurrentAnimationImagesLoad {
- [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
- }
- #endif
- @end
- #endif
|