123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // ViewController.m
- // TestGIF
- //
- // Created by huangyirong on 2020/6/2.
- // Copyright © 2020 Sogou. All rights reserved.
- //
- #import "ViewController.h"
- @import ImageIO;
- @interface ViewController ()
- @property (strong, nonatomic) UIImageView *imageView;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self test1];
-
- }
- - (void)test1
- {
- _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];
- [self.view addSubview:_imageView];
- NSString *path = [[NSBundle mainBundle] pathForResource:@"abc.gif" ofType:nil];
- NSData *data = [NSData dataWithContentsOfFile:path];
- // _imageView.image = [UIImage imageWithData:data];
- // return;
- CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
- NSInteger count = CGImageSourceGetCount(source);
- NSMutableArray *images = [NSMutableArray arrayWithCapacity:count];
- for (int i = 0; i < count; i++) {
- CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, i, NULL);
- [images addObject:[UIImage imageWithCGImage:cgImage]];
- CGImageRelease(cgImage);
- }
- CFRelease(source);
- _imageView.animationImages = images;
- _imageView.animationDuration = count * 0.1;
- [_imageView startAnimating];
- }
- @end
|