UIImageView 显示本地gif图片

首先图片要拖到项目中.

    NSString *dataPath = [[NSBundle mainBundle]pathForResource:@"xxxxx" ofType:@"gif"];

    //获取gif文件数据

    CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:dataPath], NULL);

    //获取gif文件中图片的个数

    size_tcount =CGImageSourceGetCount(source);

    //存放所有图片数组

    NSMutableArray *imageArray = [[NSMutableArray alloc] init];

    //遍历gif

    for(size_ti=0; i

       CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);

       UIImage* img = [UIImageimageWithCGImage: image];

       [imageArray addObject:img];

    }

//UIImageView播放数组动画

 UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KMainScreenWidth, 200)];

    [self.viewaddSubview:imageV];

    imageV.animationImages= imageArray;

    imageV.animationDuration = 0.4 ;

    imageV.animationRepeatCount = MAXFLOAT;

    [imageV startAnimating];


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容