---
title: "IOS播放gif图"
author: "xindrace"
date: "2012-09-10T11:10:04Z"
tags: ["gif", "iOS", "iPhone"]
categories: ["移动开发"]
slug: "ios-gif"
draft: false
lastmod: "2012-09-10T11:10:04Z"
id: 1674895
url: "https://xindrace.iteye.com/blog/1674895"
---

```
-(void)gifImageView:(NSString *)imageName
{
    NSLog(@"%@",imageName);
    // 设定位置和大小
    CGRect frame = CGRectMake(50,50,0,0);
    frame.size = [UIImage imageNamed:imageName].size;
    
    NSArray *imageArray = [imageName componentsSeparatedByString:@"."];
    
    // 读取gif图片数据
    NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[imageArray objectAtIndex:0] ofType:[imageArray objectAtIndex:1]]];
    
    // view生成
    UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
    webView.userInteractionEnabled = NO;//用户不可交互
    [webView loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
    [self.view addSubview:webView];
}
```