首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIWebView在ios-11、iPhone、Xcode-9中显示重叠状态栏。

UIWebView在ios-11、iPhone、Xcode-9中显示重叠状态栏。
EN

Stack Overflow用户
提问于 2018-05-16 06:58:20
回答 1查看 1.4K关注 0票数 0

我正在用UIWebView加载一个网络,一切都很好,除了iphoneX被切断了,在那里我放置了一个"OK“按钮和一个带有标题的标签。

代码语言:javascript
复制
    // 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)



    }

任何解决这个僵局的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-19 03:27:33

StatusBar在iPhoneX中的高度高于其他设备中的高度,因此有必要计算此高度并将此值用于WebView坐标。

  1. 添加一个视图来放置OK按钮:

@IBOutlet weak var myTopBar: UIView!

  1. 计算statusBar的高度:

//Get height status bar let statusBarHeight = UIApplication.shared.statusBarFrame.height

// to see correctly on all device models the new height will be: let heightTotal = self.myTopBar.frame.height + statusBarHeight

3:在webView中,使用这个高度:

代码语言:javascript
复制
webView = WKWebView(frame: CGRect( x: 0, y: heightTotal, width: self.view.frame.width, height: self.view.frame.height - heightTotal), configuration: WKWebViewConfiguration() )
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50364274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档