内存对比,播放的是相同的内容;在加载页面过程中明显看到WKWebView加载过程更快,UIWebView慢,有兴趣的可以试试。
加载速度对比,在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.