应用程序在所有模拟器上加载全屏。当我将它加载到我的 iPhone X 上时,它是全屏的。然而,在我妻子的 XS Max 上,我得到了下面的信箱。请帮忙!
这是我的代码。这是一个非常简单的 WebView 应用程序。
应用委托
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
return true
}
}
视图控制器
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
// MARK: - Lifecycle Methods
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
let myURL = URL(string: "https://cotta.work")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
// MARK: - Properties
lazy var webView: WKWebView = {
let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
webView.translatesAutoresizingMaskIntoConstraints = false
return webView
}()
}
extension ViewController {
func setupUI() {
self.view.addSubview(webView)
NSLayoutConstraint.activate([
webView.topAnchor
.constraint(equalTo: self.view.topAnchor),
webView.leftAnchor
.constraint(equalTo: self.view.leftAnchor),
webView.bottomAnchor
.constraint(equalTo: self.view.bottomAnchor),
webView.rightAnchor
.constraint(equalTo: self.view.rightAnchor)
])
}
}