本文也将讲解到WebKit中更新的WKWebView控件的新特性与使用方法,它很好的解决了UIWebView存在的内存、加载速度等诸多问题。
一、WKWebView新特性
- 在性能、稳定性、功能方面有很大提升(最直观的体现就是加载网页是占用的内存,模拟器加载百度与开源中国网站时,WKWebView占用23M,而UIWebView占用85M);
- 允许JavaScript的Nitro库加载并使用(UIWebView中限制);
- 支持了更多的HTML5特性;
- 高达60fps的滚动刷新率以及内置手势;
- 将UIWebViewDelegate与UIWebView重构成了14类与3个协议;
// Created by 周双建 on 15/12/21.
// Copyright © 2015年 周双建. All rights reserved.
//
#import "ViewController.h"
//要导入其框架
#import <WebKit/WKWebView.h>
#import <WebKit/WebKit.h>
typedef enum {
URL_load = 0,
HTML_load ,
Data_load ,
Fiel_load,
}WkwebLoadType;
@interface ViewController ()<WKNavigationDelegate,WKUIDelegate>
//创建一个实体变量
@property(nonatomic,strong) WKWebView * ZSJ_WkwebView;
// 加载type
@property(nonatomic,assign) NSInteger IntegerType;
// 设置加载进度条
@property(nonatomic,strong) UIProgressView * ProgressView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self makeNav];
// 创建进度条
if (!self.ProgressView) {
self.ProgressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
self.ProgressView.frame = CGRectMake(0, 64, self.view.bounds.size.width, 1);
// 设置进度条的色彩
[self.ProgressView setTrackTintColor:[UIColor clearColor]];
self.ProgressView.progressTintColor = [UIColor magentaColor];
[self.view addSubview:self.ProgressView];
}
//初始化webview
if (!self.ZSJ_WkwebView) {
//设置网页的配置文件
WKWebViewConfiguration * Configuration = [[WKWebViewConfiguration alloc]init];
//允许视频播放
Configuration.allowsAirPlayForMediaPlayback = YES;
// 允许在线播放