我对使用Xcode和Swift非常陌生。
我在使用新的WKWebView时遇到了问题。我通常使用情节提要,但我了解到Xcode 9中存在一个bug,如果您的构建包含ios 11之前的任何内容,则不允许您使用WKWebView。我了解到,如果您以编程方式添加它,这是可能的,并且一直遵循苹果的说明:
https://developer.apple.com/documentation/webkit/wkwebview
我需要能够添加Webview,同时在顶部为我创建的用作横幅的自定义视图留出空间。此俯视图的高度为116,在添加Webview之前,所有设备和方向上的约束都在起作用。
当我添加Webview并添加其自定义大小和约束时,Webview也可以在所有设备和方向上完美工作。但是,缺少我的顶部横幅视图。
我不确定我遗漏了什么,或者我是否为Webview编写了错误的代码。我会将截图和代码附加到Webview。
非常感谢您的帮助!
This is the Webview tab that is missing the banner
This is another tab that shows what the banner looks like
import UIKit
import WebKit
class FirstViewController: UIViewController, WKUIDelegate {
var myWebView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
myWebView = WKWebView(frame: .zero, configuration: webConfiguration)
myWebView.uiDelegate = self
view = myWebView
}
override func viewDidLoad() {
super.viewDidLoad()
myWebView = WKWebView(frame: CGRect( x: 0, y: 116, width: 414, height: 571), configuration: WKWebViewConfiguration() )
self.view.addSubview(myWebView)
myWebView.translatesAutoresizingMaskIntoConstraints = false
myWebView.topAnchor.constraint(equalTo: view.topAnchor, constant: 116).isActive = true
myWebView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 49).isActive = true
myWebView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
myWebView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
myWebView.widthAnchor.constraint(equalToConstant: 414).isActive = true
myWebView.heightAnchor.constraint(equalToConstant: 571).isActive = true
let myURL = URL(string: "https://apple.com")
let myRequest = URLRequest(url: myURL!)
myWebView.load(myRequest)
}