加载gif图片的方法:(需要SDWebImage方法)
/**
* 加载图片
*/
- (void)initLoadingImageView
{
NSString *name = @"loading.gif";
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
if (!self.loadingImageView) {
self.loadingImageView = [[UIImageView alloc]init];
}
// imgView.image = [UIImage animatedImageWithAnimatedGIFData:imageData];
self.loadingImageView.backgroundColor = [UIColor clearColor];
self.loadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];
self.loadingImageView.frame = CGRectMake(0, 0, 100, 250/2.0);
[self.view addSubview:self.loadingImageView];
[self.view bringSubviewToFront:self.loadingImageView];
}
iOS GIF加载技巧
本文介绍了一种使用SDWebImage库在iOS应用中加载GIF图片的方法。通过将GIF文件路径转换为NSData,并利用SDWebImage提供的API创建动画图片,最终实现GIF动图在UIImageView中的展示。
4963

被折叠的 条评论
为什么被折叠?



