WebKitView占据整个屏幕

时间:2017-10-12 18:14:28

标签: swift webkit

我有一个简单的WebKitView问题。我只在IB中设置WebKitView以显示在屏幕的底部3/4部分,但是在加载网站时占据整个页面。任何想法为什么会这样?

另外我还有另外一个问题,为什么WebView不赞成使用WebKitView比WebView更好?是否加载速度更快等?

感谢您的回复。

import UIKit
import WebKit

class ViewController: UIViewController {

@IBOutlet var webView: WKWebView!

override func loadView() {
   webView = WKWebView()

    //If you want to implement the delegate
    //webView?.navigationDelegate = self

   view = webView
}

override func viewDidLoad() {
    super.viewDidLoad()

    if let url = URL(string: "https://www.google.ca") {
        let req = URLRequest(url: url)
       webView?.load(req)
    }
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

1 个答案:

答案 0 :(得分:0)

删除loadView方法, 以下代码就足够了:)

class ViewController: UIViewController {

    @IBOutlet var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        if let url = URL(string: "https://www.google.ca") {
            let req = URLRequest(url: url)
            webView?.load(req)
        }
    }
}

enter image description here