这是我的 webview 内容的 View ,底部溢出并且不可见。我发现 webview 的父 View 覆盖了整个屏幕, subview 覆盖了整个屏幕,留下了应用程序状态栏区域。但它们都具有相同的尺寸,这就是为什么我的 subview 向下溢出。
我阅读了很多解决方案,其中大部分我都尝试过,但没有发现任何区别。
我正在加载的 html 文件
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, heigth=device-height, width=device-width">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta charset="utf-8">
<title>XYZ</title>
<base href=".">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<root id="app-root"></root>
<script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body>
</html>
webkit View
static func getWebKitView(uiController : ViewController, handlerName : String) -> WKWebView {
let controller = WKUserContentController()
controller.add(uiController as! WKScriptMessageHandler, name: handlerName)
let config = WKWebViewConfiguration()
config.userContentController = controller
let webKitView = WKWebView(frame: .init(x: 0.0, y: 0.0, width: DeviceInfo().getDeviceBounds().w, height: DeviceInfo().getDeviceBounds().h-2), configuration: config)
webKitView.backgroundColor = UIColor.yellow
webKitView.scrollView.isScrollEnabled = false
// webKitView.frame.size = webKitView.scrollView.contentSize
webKitView.scrollView.contentSize = webKitView.frame.size
webKitView.allowsBackForwardNavigationGestures = true
return webKitView
}
如何解决这个 UI 问题
最佳答案
将 Web Kit View 的高度设置为比设备边界小 100 点
然后给你的 subview y 位置 heightOfYourWebView + 10 所以按钮将在 WebkitView 下方和屏幕底部上方也给宽度 350 和按钮的高度 30 并且 View 不会消失界限
关于javascript - webkit View 内容高度溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522959/