iOS WKWebView状态栏填充 [英] iOS WKWebView Status Bar Padding

查看:1798
本文介绍了iOS WKWebView状态栏填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无休止地寻找有效的答案。我正在尝试创建一个非常简单的WKWebView应用程序来包装Web应用程序。我不需要任何花哨的东西,因为导航控件都在应用程序中。



目前我的ViewController.swift文件如下所示:





任何帮助都会非常感激,因为我是iOS开发的新手。我还希望能够更改状态栏颜色,但目前不是一个直接关注的问题。

解决方案

我使用autolayout约束解决了这个问题,请检查

  import UIKit 
import WebKit

class ViewController:UIViewController,WKUIDelegate {

var webView:WKWebView!


覆盖func viewDidLoad(){
super.viewDidLoad()


setupWebView()

let url = URL(字符串:https://www.google.com)
let request = URLRequest(url:url!)
webView.load(request)
}

func setupWebView(){
let webConfiguration = WKWebViewConfiguration()

webView = WKWebView(frame:.zero,configuration:webConfiguration)
webView.uiDelegate = self
// view = webView
view.addSubview(webView)
webView.translatesAutoresizingMaskIntoConstraints = false

view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat:H: | [v0] |,options:NSLayoutFormatOptions(),metrics:nil,views:[v0:webView]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat:V:| -20- [ v0] |,选项:NSLayoutFormatOpt ions(),metrics:nil,views:[v0:webView]))
}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理可以重新创建的任何资源。
}
}


希望它有所帮助。


I have been endlessly searching for an answer for this that works. I am trying to create a very simple WKWebView application to wrap out web app. I don't need anything fancy as navigation controls are all within the application.

Currently my ViewController.swift file looks like this:

https://gist.github.com/andrewweaver/4a0e13245f185e8f31ba812b91f7dddd

Swift version: Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)

The issue is the padding for the status bar, I would like to adjust it so that the status bar wasn't on top of the content as it is here:

Any help would be greatly appreciated as I am very new to iOS development. I would also like to be able to change the status bar color, but it isn't an immediate concern at this time.

解决方案

I solved this problem using autolayout constraints, Please check

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

        var webView: WKWebView!


        override func viewDidLoad() {
            super.viewDidLoad()


            setupWebView()

            let url = URL(string: "https://www.google.com")
            let request = URLRequest(url: url!)
            webView.load(request)
    }

    func setupWebView() {
            let webConfiguration = WKWebViewConfiguration()

            webView = WKWebView(frame:.zero , configuration: webConfiguration)
            webView.uiDelegate = self
            //view = webView
            view.addSubview(webView)
            webView.translatesAutoresizingMaskIntoConstraints = false

            view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":webView]))
            view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-20-[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":webView]))
    }

        override func didReceiveMemoryWarning() {
                super.didReceiveMemoryWarning()
                // Dispose of any resources that can be recreated.
        }
}

Hope it helps.

这篇关于iOS WKWebView状态栏填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆