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];


你可能感兴趣的:(UIImageView 显示本地gif图片)