WebkitView内容高度溢出

时间:2019-02-04 19:22:22

标签: javascript ios css swift wkwebview

image

这是我的Webview内容的视图,其底部溢出并且不可见。我发现Webview的父视图覆盖了整个屏幕,子视图覆盖了整个屏幕,留下了应用程序状态栏区域。但这两个尺寸相等,这就是为什么我的子视图向下溢出的原因。

我阅读了许多解决方案,其中大多数我都尝试过,但没有发现任何区别。

我正在加载的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视图

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问题

1 个答案:

答案 0 :(得分:0)

让Web Kit的高度比设备范围少100点

,然后将您的子视图的y位置指定为heightOfYourWebView + 10,因此Button将位于WebkitView下方,并且位于屏幕底部上方,还将width设置为350,button的高度设置为30,并且视图不会消失范围

相关问题