[英]Migrate UIWebView to WKWebView
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. 在我的iOS应用程序中,我尝试将旧的UIWebView代码迁移到WKWebView,因为从理论上讲,WKWebView比UIWebView更快,更高效。
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? 有人可以指出我的简单教程,也可以在注释中解释如何通过编程将代码转换为WKWebView吗? thanks in advance.
提前致谢。
View Controller.swift: 查看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)
Add " WebKit " framework to your class. 在您的课程中添加“ WebKit ”框架。
Please refer the below code 请参考以下代码
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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.