UIWebView在ios-11,iPhone-X,Xcode-9中显示重叠的状态栏 [英] UIWebView show overlapping status bar in ios-11, iPhone-X, Xcode-9
问题描述
我正在使用UIWebView加载网站,但一切正常,除了将iphoneX剪掉了放置确定"按钮和带有标题的标签的栏之外.
I'm loading a web with UIWebView, everything works fine except that the iphoneX is cut off the bar where I put an "OK" button and a label with a title.
// webView
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://google.com")
let myRequest = URLRequest(url: myURL!)
webView = WKWebView(frame: CGRect( x: 0, y: 60, width: self.view.frame.width, height: self.view.frame.height - 60 ), configuration: WKWebViewConfiguration() )
//webView.backgroundColor = UIColor.blue
self.view.addSubview(webView)
webView.load(myRequest)
self.webView.allowsBackForwardNavigationGestures = true
//hide navegation bar
self.navigationController?.setNavigationBarHidden(true, animated: true)
// add cornerRadius to view
navegador.layer.cornerRadius = 10
//add observer to get estimated progress value
self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)
}
任何解决这一僵局的建议.
Any suggestions to solve this impasse.
推荐答案
iPhoneX中StatusBar的高度高于其他设备,因此有必要计算该高度并将其用于WebView坐标.
The height of the StatusBar in the iPhoneX is higher than in the other devices, it is necessary to calculate this height and use this value for the WebView coordinates.
- 添加视图以放置确定"按钮:
@IBOutlet弱var myTopBar:UIView!
- 计算statusBar的高度:
//获取高度状态栏让statusBarHeight = UIApplication.shared.statusBarFrame.height
//为了正确显示所有设备型号,新高度将为:让heightTotal = self.myTopBar.frame.height + statusBarHeight
3:在webView中,使用以下高度:
3: In the webView, use this height:
webView = WKWebView(frame: CGRect( x: 0, y: heightTotal, width: self.view.frame.width, height: self.view.frame.height - heightTotal), configuration: WKWebViewConfiguration() )
这篇关于UIWebView在ios-11,iPhone-X,Xcode-9中显示重叠的状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!