一,UIWebview加载
核心代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
#pragma mark- 使用uiwebview加载gif
/*
NSData *data = [NSData dataWithContentsOfFile:path];
使用loadData:MIMEType:textEncodingName: 则有警告
[webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
*/
webView = [[UIWebView alloc] initWithFrame:CGRectZero];
webView.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"earth1" ofType:@"gif"];
NSURL *url = [NSURL URLWithString:path];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:webView];
//加载xib
aaView = [LoginView loadLoginView];
aaView.backgroundColor = [UIColor clearColor];
[aaView setFrame:self.view.bounds];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView setFrame:self.view.bounds];
[self.view addSubview:aaView];
}
注意:
上面的xib也就是,登录自定义view要在webview请求完之后再加上去,否则会出现白屏一闪之后再到正常。(原因其实很简单,webview请求数据是需要点时间的)
还有使用webview加载gif,无法设置动画间隔时间
二,SDWebImage加载
注意SDWebImage4.0之后,加载gif方式的更新,新方法如下截图:
示例代码:
#import "FLAnimatedImageView.h"
#import "FLAnimatedImage.h"
FLAnimatedImageView *imgView = [FLAnimatedImageView new];
[view addSubview:imgView];
NSString* filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"loading" ofType:@"gif"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
imgView.backgroundColor = [UIColor clearColor];
imgView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
其它方法
一些第三方框架等
效果图:
图片来自网络,侵权立删
网友评论