简体   繁体   English

iPhone XR 中的 WKWebView 重叠状态栏

[英]WKWebView overlapping status bar in iPhone XR

I have a WKWebView view in my App, which renders content developed in Ionic framework.我的应用程序中有一个 WKWebView 视图,它呈现在 Ionic 框架中开发的内容。 Seemingly all Apple devices except the X models (which have a taller status bar) behave well with no overlapping the status bar.似乎除了 X 型号(具有更高的状态栏)之外的所有 Apple 设备都表现良好,没有与状态栏重叠。 But the "X" models have a problem.但是“X”型号有一个问题。

I have set its constraints as:我已将其约束设置为:

Interface builder constraints image界面构建器约束图像

However, the result is that these constraints are not being enforced, when the modal window shows up it extends beyond the status bar boundary in both the iPhone XR, X, XS simulator and physical device, making it almost impossible to access the "exit out" button to close the modal window.然而,结果是这些约束没有被强制执行,当模态 window 显示它超出 iPhone XR、X、XS 模拟器和物理设备的状态栏边界时,几乎不可能访问“退出" 按钮关闭模态 window。

App displaying issue应用显示问题

Could it be a problem in the Ionic code itself, or is it more something like I have to fix in XCode somehow?这可能是离子代码本身的问题,还是更像是我必须以某种方式在 XCode 中修复?

I have looked at: UIWebView show overlapping status bar in ios-11, iPhone-X, Xcode-9我看过: UIWebView 在 ios-11、iPhone-X、Xcode-9 中显示重叠的状态栏

But it seems that trying to adjust the view programmatically is not working, as I tried to add this code in loadView() and viewDidLoad() of my ViewController to no avail (I get ERR BAD ACCESS when trying to find the frame height of the view in order to adjust it in relation to the StatusBar) - iOS 13, Swift 5:但似乎尝试以编程方式调整视图不起作用,因为我试图在我的 ViewController 的 loadView() 和 viewDidLoad() 中添加此代码无济于事(我在尝试查找框架高度时得到 ERR BAD ACCESS查看以根据状态栏调整它) - iOS 13、Swift 5:

override func loadView() {
    
    let webConfiguration = WKWebViewConfiguration()
    
    #if false
    
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    #else
    
    //First, let's find out the height of the status bar, so we don't invade it.
    let winScene = UIApplication.shared
                    .connectedScenes
                    .first
    
    let windowScene = winScene as! UIWindowScene
    
    let sbHeight = windowScene.statusBarManager?.statusBarFrame.height
    let heightTotal = view.frame.height + sbHeight!
    
    webView = WKWebView(frame: CGRect( x: 0, y: heightTotal, width: view.frame.width, height: view.frame.height - sbHeight!), configuration: webConfiguration )

    #endif
    
    webView.uiDelegate = self
    view = webView
    
       }

Running out of ideas, so any tips are appreciated.想法不多了,所以任何提示都值得赞赏。

Add constraints like this:添加这样的约束:

在此处输入图像描述

Use the following code in the ViewController:在 ViewController 中使用以下代码:

import UIKit
import WebKit

class ViewController: UIViewController {

    @IBOutlet weak var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myURL = URL(string:"https://www.apple.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}

So remember to add the WebKit framework:所以记得添加 WebKit 框架:

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

This way I get the view correctly using iPhone 11 Pro simulator.这样我就可以使用 iPhone 11 Pro 模拟器正确获取视图。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM