我想创建一个仅加载我的移动友好网站的ios应用。我有以下代码:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.scrollView.isScrollEnabled = true
webView.scrollView.bounces = false
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://google.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
现在我面临的问题是,当您向下滚动页面时,状态栏下方会显示一些部分,我最好不要这些部分。我该如何解决?
答案 0 :(得分:0)
在ViewController(此处添加了Webview)中,仅在“大小检查器”中使用自动调整大小选项(在viewController-view中,以编程方式稍后执行时添加Webview),而没有使用限制:
我在Webview的viewcontroller中的代码是:
var webView2: UIWebView?
var hasConfiguredView = false
var screenSize = CGRect.zero
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
screenSize = UIScreen.main.bounds
webView.frame.origin.x = 0
webView.frame.origin.y = 0
webView.frame.size.height = screenSize.height
webView.frame.size.width = screenSize.width
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if !hasConfiguredView {
hasConfiguredView = true
drawenormalwebview()
}
}
private func drawenormalwebview(){
let urlstring = "https://google.com"
webView2 = UIWebView.init()
webView2!.frame.origin.x = 0
webView2!.frame.origin.y = 0.f
webView2!.frame.size.height = screenSize.height
webView2!.frame.size.width = screenSize.width
webView2!.delegate = self
webView2!.scrollView.bounces = false
self.view.addSubview(webView2!)
webView2!.isOpaque = false
webView2!.backgroundColor = UIColor.clear
if let urls = URL(string: urlstring) {
let myRequest = URLRequest(url: urls,
cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 5.0)
webView2!.loadRequest(myRequest)
}
}