当我将WKWebView
放入NSViewRepresentable
时遇到问题,然后我的应用显示黑屏而不是加载的网页。
import SwiftUI
import WebKit
struct TestView : NSViewRepresentable {
func makeNSView(context: Context) -> WKWebView {
let view = WKWebView()
if let url = URL(string: "https://www.google.com/") {
view.load(URLRequest(url: url))
}
return view
}
func updateNSView(_ view: WKWebView, context: Context) {
}
}
struct ContentView: View {
var body: some View {
TestView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}