将 UIWebView 迁移到 WKWebView [英] Migrate UIWebView to WKWebView
问题描述
在我的 iOS 应用程序中,我试图将我的旧 UIWebView 代码迁移到 WKWebView,因为理论上 WKWebView 比 UIWebView 更快、更有效.
Within my iOS app I am attempting to migrate my old UIWebView code to WKWebView since WKWebView is, in theory, faster and more efficient than UIWebView.
我看过一堆教程(比如这里和此处 和此处) 在互联网上,但找不到任何解释如何简单地以编程方式将 WKWebView 添加到我的应用程序的内容.
I have looked at a bunch of tutorials (like here and here and here) on the internet but cant find anything that explains how to simply add a WKWebView to my app progmatically.
有人能给我指出一个简单的教程或在评论中解释如何以编程方式将此代码转换为 WKWebView 吗?提前致谢.
Can someone point me to a simple tutorial or explain in the comments how to convert this code to WKWebView progmatically? thanks in advance.
视图控制器.swift:
View Controller.swift:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let myWebView:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.communionchapelefca.org/app-home")!))
self.view.addSubview(myWebView)
推荐答案
将WebKit"框架添加到您的类.
Add "WebKit" framework to your class.
请参考以下代码
import UIKit
import WebKit
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myWebView:WKWebView = WKWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.communionchapelefca.org/app-home")!))
self.view.addSubview(myWebView)
}
}
这篇关于将 UIWebView 迁移到 WKWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!