【发布时间】:2020-01-21 15:40:18
【问题描述】:
在 iOS12 下,以下代码在 WKWebView 中显示透明背景。
但是,在 iOS13 下,情况不再如此——为什么?以及如何再次实现透明背景?
我试过了
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.scrollView.bounces = false
webView.navigationDelegate = self
let body =
"<html>\n" +
"<head>\n" +
"<style>\n" +
"html { margin: 0; }" +
"body { margin: 0; font-family: Avenir-Light; font-size: 41; color: white; background-color: transparent }\n" +
"a, a:active, a:visited, a:hover { color: #FFED00 }\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
article.body +
"</body>\n"
"</html>"
webView.loadHTMLString(body, baseURL: nil)
}
添加以下内容没有帮助...
webView.isOpaque = false
webView.backgroundColor = .clear
奇怪的是,如果我设置透明以外的背景颜色,那么它会起作用:
即通过替换以下内容,我得到了红色背景:
"body { margin: 0; font-family: Avenir-Light; font-size: 41; color: white; background-color: red }\n"
为什么transparent 不起作用??? (我也试过clear- 但没有成功)
【问题讨论】:
-
刚刚遇到了同样的问题。除了它不只是 iOS 13,而是与 Xcode 11 有关。使用 Xcode 10 构建的应用程序在具有透明背景的 iOS 13 上运行(即 WKWebView 之一)。如果我使用 Xcode 11 构建应用程序,它在 iOS 11 上具有透明背景,但在 iOS 13 上没有。
-
好的,再调查一下。 Xcode 11 + iOS 13 模拟器 = 没有透明背景。 Xcode 11 + 运行 iOS 13 的真实设备 = 透明背景。
-
好的,更多信息。我的真实设备实际上运行的是 13.1,但模拟器仅适用于 13.0。
-
在真实设备上试用 13.0 - 可重现,13.1 - 不可重现。 Apple 方面的许多错误之一,很确定在代码方面没有什么可以解决的。
标签: html uiwebview wkwebview ios13 swift5.1