diff --git a/README.md b/README.md index 58e9d56..bfab1b0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - Web Image ========= @@ -9,6 +8,7 @@ It provides: - An UIImageView category adding web image and cache management to the Cocoa Touch framework - An asynchronous image downloader - An asynchronous memory + disk image caching with automatic cache expiration handling +- Animated GIF support - A background image decompression - A guarantee that the same URL won't be downloaded several times - A guarantee that bogus URLs won't be retried again and again diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 6746a37..df86c32 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -183,7 +183,8 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week { if ([data isGIF]) { - return [UIImage animatedGIFWithData:data]; + UIImage *image = [UIImage animatedGIFWithData:data]; + return [self scaledImageForKey:key image:image]; } else { diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index 6d54e51..e88f9fa 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -14,21 +14,35 @@ inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { - if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) + if ([image.images count] > 0) { - CGFloat scale = 1.0; - if (key.length >= 8) + NSMutableArray *scaledImages = [NSMutableArray array]; + + for (UIImage *tempImage in image.images) { - // Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext) - NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)]; - if (range.location != NSNotFound) - { - scale = 2.0; - } + [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; } - - UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; - image = scaledImage; + + return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; + } + else + { + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) + { + CGFloat scale = 1.0; + if (key.length >= 8) + { + // Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext) + NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)]; + if (range.location != NSNotFound) + { + scale = 2.0; + } + } + + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; + image = scaledImage; + } + return image; } - return image; }