ITeye博客

IOS播放gif图

xindrace · 2012-09-10 11:10 · IOS · 移动开发 · iOS · iPhone · gif · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。