【iOS开发】WKWebView学习笔记(4)
2016-09-07 本文已影响0人
extanstory
内存对比,播放的是相同的内容;在加载页面过程中明显看到WKWebView加载过程更快,UIWebView慢,有兴趣的可以试试。
![Snip20160906_10.png](https://img.haomeiwen.com/i2854558/c1e8a472fe21f1ac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
加载速度对比,在touch begin中添加定时器,观察加载完毕时,能打印多少次。
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
WKWebView *web = [[WKWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:web];
web.navigationDelegate = self;
// web.UIDelegate = self;
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(test)];
[self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
self.web = web;
}
- (void)test{
NSLog(@"--%ld",self.count);
self.count ++;
}
// 页面加载完毕时调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
NSLog(@"页面加载完毕时调用");
[self.link invalidate];
}
WKWebView5次平均70次左右,UIWebView 5次平均120次左右。(模拟器测试的)
刷新fps2个控件基本都在60.
![Snip20160907_14.png](https://img.haomeiwen.com/i2854558/d1235c1805ba09b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)