iOS webView 没有使用整个屏幕

iOS webView is not using whole screen

我尝试在 webView 应用程序中显示一个完整的响应式 bootstrap 网站。该应用程序应该只加载我的网站,就像我在 smartphone/tablet.

的浏览器中加载网站一样

但是,该应用在平板电脑上看起来像这样:

如何让应用程序完全响应?

完整代码:

ViewController.swift

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {

    @IBOutlet var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // 1  The webView loads the url using an URLRequest object.
        let url = URL(string: "https://www.blizz-z.de/")!

        webView.load(URLRequest(url: url))

        // 2  A refresh item is added to the toolbar which will refresh the current webpage.
        let refresh = UIBarButtonItem(
            barButtonSystemItem: .refresh,
            target: webView,
            action: #selector(webView.reload)
        )

        toolbarItems = [refresh]
        navigationController?.isToolbarHidden = true
        navigationController?.isNavigationBarHidden = true

    }

    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
        let color = UIColor.black;
        self.view.backgroundColor = color
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        title = webView.title
    }



}
import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {

 @IBOutlet var webView: WKWebView!

 override func viewDidLoad() {
    super.viewDidLoad()
    self.setupWebview()
    let refresh = UIBarButtonItem(
        barButtonSystemItem: .refresh,
        target: webView,
        action: #selector(webView.reload)
    )

    toolbarItems = [refresh]
    navigationController?.isToolbarHidden = true
    navigationController?.isNavigationBarHidden = true

 }


 func setupWebview(){
    self.webView.frame = UIScreen.main.bounds
    self.webView.navigationDelegate = self
    self.view.backgroundColor = UIColor.black
    let url = URL(string: "https://www.blizz-z.de/")!
    self.webView.load(URLRequest(url: url))
 }


 func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
     title = webView.title
 }
}

试试这个...(注意:不是复制粘贴代码)

你的代码没有问题。
切换到 Xcode 中的目标设置,在 "General" 部分中的选项卡上 "Deployment target" 切换 "Devices" 到 "Universal"。
如果没有添加 "Launch Screen.storyboard" 也请添加。

你应该给webView添加约束,top/bottom/left/right约束的常量是0到superView,不是safe area