updated formatting for project

This commit is contained in:
Andy LaVoy 2013-04-28 14:59:33 -07:00
parent 5bf37d5472
commit 2a370b062b
5 changed files with 54 additions and 31 deletions

View File

@ -10,13 +10,15 @@
@implementation NSData (GIF)
- (BOOL)isGIF {
- (BOOL)isGIF
{
BOOL isGIF = NO;
uint8_t c;
[self getBytes:&c length:1];
switch (c) {
switch (c)
{
case 0x47: // probably a GIF
isGIF = YES;
break;

View File

@ -181,9 +181,12 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
NSData *data = [NSData dataWithContentsOfFile:path];
if (data)
{
if ([data isGIF]) {
if ([data isGIF])
{
return [UIImage animatedGIFWithData:data];
} else {
}
else
{
UIImage *image = [[UIImage alloc] initWithData:data];
UIImage *scaledImage = [self scaledImageForKey:key image:image];
return [UIImage decodedImageWithImage:scaledImage];

View File

@ -123,7 +123,8 @@
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
BOOL imageIsGIF = [data isGIF];
if (imageIsGIF) {
if (imageIsGIF)
{
downloadedImage = [UIImage animatedGIFWithData:data];
}

View File

@ -11,8 +11,10 @@
@implementation UIImage (GIF)
+(UIImage*)animatedGIFWithData:(NSData *)data {
if (!data) {
+ (UIImage *)animatedGIFWithData:(NSData *)data
{
if (!data)
{
return nil;
}
@ -23,7 +25,8 @@
NSTimeInterval duration = 0.0f;
for (size_t i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++)
{
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
NSDictionary *frameProperties = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, i, NULL));
@ -36,22 +39,26 @@
CFRelease(source);
if (!duration) {
if (!duration)
{
duration = (1.0f/10.0f)*count;
}
return [UIImage animatedImageWithImages:images duration:duration];
}
+(UIImage*)animatedGIFNamed:(NSString *)name {
+ (UIImage *)animatedGIFNamed:(NSString *)name
{
CGFloat scale = [UIScreen mainScreen].scale;
if (scale > 1.0f) {
if (scale > 1.0f)
{
NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
NSData *data = [NSData dataWithContentsOfFile:retinaPath];
if (data) {
if (data)
{
return [UIImage animatedGIFWithData:data];
}
@ -59,18 +66,21 @@
data = [NSData dataWithContentsOfFile:path];
if (data) {
if (data)
{
return [UIImage animatedGIFWithData:data];
}
return [UIImage imageNamed:name];
}
else {
else
{
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
NSData *data = [NSData dataWithContentsOfFile:path];
if (data) {
if (data)
{
return [UIImage animatedGIFWithData:data];
}
@ -78,8 +88,10 @@
}
}
-(UIImage*)animatedImageByScalingAndCroppingToSize:(CGSize)size {
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
- (UIImage *)animatedImageByScalingAndCroppingToSize:(CGSize)size
{
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero))
{
return self;
}
@ -91,9 +103,13 @@
CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor :heightFactor;
scaledSize.width = self.size.width * scaleFactor;
scaledSize.height = self.size.height * scaleFactor;
if (widthFactor > heightFactor) {
if (widthFactor > heightFactor)
{
thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
} else if (widthFactor < heightFactor) {
}
else if (widthFactor < heightFactor)
{
thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
}
@ -101,7 +117,8 @@
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
for (UIImage* image in self.images) {
for (UIImage *image in self.images)
{
[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();