【问题标题】:WebKit support lower version of iOSWebKit 支持较低版本的 iOS
【发布时间】:2018-07-11 05:58:43
【问题描述】:

我正在尝试在我的应用程序中添加 webView。

在低版本的iOS中,webView在状态栏的后面。在iOS 11及更高版本中,webView定位正确。为什么在低版本的iOS中定位不正确? 如何在支持所有 iOS 设备的 webView 和状态栏之间添加空间?

这是我的代码

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self
    view = webView  
}

我尝试添加边距和顶部约束。它不起作用。

  let margins = view.layoutMarginsGuide
  webView.topAnchor.constraint(equalTo: margins.bottomAnchor,constant : 200).isActive = true
  view.layoutMargins = UIEdgeInsets(top: 164, left: 0, bottom: 0, right: 0)

希望你能理解我的问题。 提前致谢。

【问题讨论】:

    标签: ios swift statusbar margins


    【解决方案1】:

    我用它来定位我的网页:

    override func viewDidAppear(_ animated: Bool)
    {
        if #available(iOS 11.0, *)
        {
            allStack.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
        }
        else
        {
            allStack.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
        }
    }
    

    allStack 是 UIStackView,其中包含我的自定义导航栏和 WKWebView。

    如果小于iOS 11,则将整个视图从顶部20点定位,否则将其放置到安全区域。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多