加载一张gif动态图
来源:互联网 发布:网卡的mac地址 编辑:程序博客网 时间:2024/06/10 14:10
不知道大家有没有碰到过加载一张gif图的问题 这里我整理了两个方法第一个是通过html 加载到一个Web上 另一个是通过SDWebImage来实现的 其实两个原理都是差不多的 使用第三方可能比较简单 但是大家可以可以自己写一下,话不多说上代码:
第一种方法:
[super.navigationController setNavigationBarHidden:YES animated:TRUE];
webView = [[UIWebView alloc]init];
webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
// 设定位置和大小
NSString *html = [NSString stringWithFormat:@"<html><head><style>body{margin:0px;padding:0px}</style></head><body><img border=\"0\" src = \"searchwait.gif\" width=\"%f\"height=\"%f\" style=\"position: absolute; z-index: -1;margin:0px;padding:0px\"><body></head></html>",self.view.bounds.size.width,self.view.bounds.size.height];
NSString *path = [[NSBundle mainBundle] pathForResource:@"searchwait"ofType:@"gif"];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:html baseURL:baseURL];
webView.userInteractionEnabled = NO;
webView.backgroundColor = wc_white;
webView.contentMode = UIViewContentModeScaleAspectFill;
webView.clipsToBounds = YES;
[self.view addSubview:webView];
第二种方法:
- (void)initLoadingImageView
{
NSString *name =@"loading.gif";
NSString *filePath = [[NSBundlebundleWithPath:[[NSBundlemainBundle]bundlePath]]pathForResource:nameofType:nil];
NSData *imageData = [NSDatadataWithContentsOfFile: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];
}
- 加载一张gif动态图
- Gif动态图加载
- 动态加载Gif图-Glide
- glide加载gif动态图
- iOS-OC-启动图加载动态Gif
- android-gif-drawable 加载太多的gif,有时gif动态图不动
- iOS开发之初:根据一张gif图,返回其中每一帧的图片数组(ImageView加载gif))
- iOS加载GIF动态图片
- UIImageView加载动态gif图片
- Photoshop合并多张jpg为一张动态GIF
- 加载gif动图
- Android加载gif图
- 显示GIF动态图
- GIF动态图制作
- Gif动态图显示
- Gif动态图
- GIF动态图制作
- VC中加载GIF格式动态图片
- Mybatis事务管理
- AngularJs + angular-ui-router + bootstrap 实现基础导航栏
- el表达式
- CSS3,背景透明
- LeetCode 040 Combination Sum II
- 加载一张gif动态图
- [c++]Xcode配置gtest
- 由于权限不足而无法读取配置文件出现的HTTP 500.19解决办法
- RxJava学习小结
- idea设置行号
- libevent源码学习研究(libevent-0.1)
- Ion—-另外添加参数
- oracle 中并行度的设置需要考虑的因素
- 大公司还是小公司