标签:
WKWebView 是IOS8新增的 Web浏览视图
优点: 加载速度 比UIWebView提升差不多一倍的, 内存使用上面,反而还少了一半。
缺点: WKWebView 不支持缓存 和 NSURLProtocol 拦截了
我建议如果对缓存不高的页面可以使用,用户体验会提高很多。
由于项目中以前都是用 UIWebView 而且还要兼容 IOS8 之前的机子。 所以 我创建了一个新类 IMYWebView 你只要全局替换 UIWebView 就能无缝升级到 WKWebView 啦
IMYWebView.h 中的API 会在内部自动支持 UIWebView 和 WKWebView,
title,estimatedProgress 是我认为 WKWebView 中比较有用的新增API
- @interface IMYVKWebView : UIView
-
- - (instancetype)initWithFrame:(CGRect)frame usingUIWebView:(BOOL)usingUIWebView;
-
- @property(weak,nonatomic)id<IMYVKWebViewDelegate> delegate;
-
- @property (nonatomic, readonly) id realWebView;
- @property (nonatomic, readonly) BOOL usingUIWebView;
- @property (nonatomic, readonly) double estimatedProgress;
-
- @property (nonatomic, readonly) NSURLRequest *originRequest;
-
- - (NSInteger)countOfHistory;
- - (void)gobackWithStep:(NSInteger)step;
-
- @property (nonatomic, readonly) UIScrollView *scrollView;
-
- - (id)loadRequest:(NSURLRequest *)request;
- - (id)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;
-
- @property (nonatomic, readonly, copy) NSString *title;
- @property (nonatomic, readonly) NSURLRequest *currentRequest;
- @property (nonatomic, readonly) NSURL *URL;
-
- @property (nonatomic, readonly, getter=isLoading) BOOL loading;
- @property (nonatomic, readonly) BOOL canGoBack;
- @property (nonatomic, readonly) BOOL canGoForward;
-
- - (id)goBack;
- - (id)goForward;
- - (id)reload;
- - (id)reloadFromOrigin;
- - (void)stopLoading;
-
- - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler;
- - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javaScriptString __deprecated_msg("Method deprecated. Use [evaluateJavaScript:completionHandler:]");
-
- @property (nonatomic) BOOL scalesPageToFit;
-
- @end
代码地址 https://github.com/wangyangcc/IMYWebView
iOS开发之UIWebView 无缝切换到 WKWebView (IMYWebView)
标签:
原文地址:http://www.cnblogs.com/lys-iOS-study/p/5802339.html