在 iOS 中加载 webview 之前需要删除白屏,尝试了 webview 不透明。 即使添加了启动屏幕和启动屏幕后,在加载 Webview URL 之前我仍然会看到白色的启动屏幕。
import UIKit
import WebKit
class HomeViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
webView.isOpaque = false
}
override func viewDidLoad() {
super.viewDidLoad()
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.translatesAutoresizingMaskIntoConstraints = false
let myURL = URL(string:"https://google.com")
let myRequest = URLRequest(url: myURL!)
view.addSubview(webView)
webView.load(myRequest)
NSLayoutConstraint.activate([
webView.topAnchor.constraint(equalTo: view.topAnchor),
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
webView.leftAnchor.constraint(equalTo: view.leftAnchor),
webView.rightAnchor.constraint(equalTo: view.rightAnchor)
])}
}
你尝试过去掉webView的背景色吗?
webView.backgroundColor = .clear
你尝试过吗
self.webView.scrollView.backgroundColor = .clear
//Xcode13
webView.isOpaque = false;
webView.backgroundColor = UIColor.clear;
任何正在寻找 appkit 的 macOS 解决方案的人,请尝试这个。
webview.setValue(false, forKey: "drawsBackground")
这在 Xcode 15、Ventura 13.5.2 中对我有用