在我的 iOS 应用程序中,我尝试将旧的 UIWebView 代码迁移到 WKWebView,因为理论上 WKWebView 比 UIWebView 更快、更高效。
我看过很多教程(比如here https://stackoverflow.com/questions/25665141/migrate-to-wkwebview and here https://stackoverflow.com/questions/25665141/migrate-to-wkwebview and here https://stackoverflow.com/questions/26027100/wkwebview-add-to-subview)在互联网上,但找不到任何解释如何简单地以编程方式将 WKWebView 添加到我的应用程序的内容。
有人可以给我指一个简单的教程或在评论中解释如何以编程方式将此代码转换为 WKWebView 吗?提前致谢。
查看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“你的班级的框架。
请参考下面的代码
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)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)