Authored by Bogdan Poplauschi
Committed by GitHub

Merge pull request #1975 from dreampiggy/mac_animate_gif

support animated GIF on macOS
@@ -27,6 +27,8 @@ @@ -27,6 +27,8 @@
27 // NOTE: https links or authentication ones do not work (there is a crash) 27 // NOTE: https links or authentication ones do not work (there is a crash)
28 28
29 // Do any additional setup after loading the view. 29 // Do any additional setup after loading the view.
  30 + // For animated GIF rendering, set `animates` to YES or will only show the first frame
  31 + self.imageView1.animates = YES;
30 [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]]; 32 [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]];
31 [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]]; 33 [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]];
32 [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]]; 34 [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
@@ -92,7 +92,7 @@ imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.jpg @@ -92,7 +92,7 @@ imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.jpg
92 - If you use cocoapods, add `pod 'SDWebImage/GIF'` to your podfile. 92 - If you use cocoapods, add `pod 'SDWebImage/GIF'` to your podfile.
93 - To use it, simply make sure you use `FLAnimatedImageView` instead of `UIImageView`. 93 - To use it, simply make sure you use `FLAnimatedImageView` instead of `UIImageView`.
94 - **Note**: there is a backwards compatible feature, so if you are still trying to load a GIF into a `UIImageView`, it will only show the 1st frame as a static image. 94 - **Note**: there is a backwards compatible feature, so if you are still trying to load a GIF into a `UIImageView`, it will only show the 1st frame as a static image.
95 -- **Important**: FLAnimatedImage only works on the iOS platform, so for all the other platforms (OS X, tvOS, watchOS) we will fallback to the backwards compatibility feature described above 95 +- **Important**: FLAnimatedImage only works on the iOS platform. For OS X, use `NSImageView` with `animates` set to `YES` to show the entire animated images and `NO` to only show the 1st frame. For all the other platforms (tvOS, watchOS) we will fallback to the backwards compatibility feature described above
96 96
97 ## Common Problems 97 ## Common Problems
98 98
@@ -19,6 +19,10 @@ @@ -19,6 +19,10 @@
19 return nil; 19 return nil;
20 } 20 }
21 21
  22 +#if SD_MAC
  23 + return [[UIImage alloc] initWithData:data];
  24 +#endif
  25 +
22 CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); 26 CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
23 27
24 size_t count = CGImageSourceGetCount(source); 28 size_t count = CGImageSourceGetCount(source);
@@ -42,8 +46,6 @@ @@ -42,8 +46,6 @@
42 #if SD_UIKIT || SD_WATCH 46 #if SD_UIKIT || SD_WATCH
43 UIImage *frameImage = [UIImage imageWithCGImage:CGImage scale:scale orientation:UIImageOrientationUp]; 47 UIImage *frameImage = [UIImage imageWithCGImage:CGImage scale:scale orientation:UIImageOrientationUp];
44 staticImage = [UIImage animatedImageWithImages:@[frameImage] duration:0.0f]; 48 staticImage = [UIImage animatedImageWithImages:@[frameImage] duration:0.0f];
45 -#elif SD_MAC  
46 - staticImage = [[UIImage alloc] initWithCGImage:CGImage size:NSZeroSize];  
47 #endif 49 #endif
48 CGImageRelease(CGImage); 50 CGImageRelease(CGImage);
49 } 51 }