IOS播放gif图

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

猜你喜欢

转载自xindrace.iteye.com/blog/1674895