I've created a simple test app to reproduce my problem reliably and minimize the moving parts. It contains just a navigation controller and a view controller that I add a WKWebView to. I immediately tell that WKWebView to navigate to www.google.ca. Once the page has loaded, the content automatically jumps up underneath the header bar. This is reproducible consistently on various simulators/devices running iOS 8/9/9.1. Below is the code for my ViewController:
// ViewController.swift
import UIKit
import WebKit
class ViewController: UIViewController {
let webView = WKWebView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(webView)
let url = NSURL(string: "http://www.google.ca")!
let request = NSURLRequest(URL: url)
webView.loadRequest(request)
webView.frame = view.bounds
}
}
Once we have the local web file URL we can use the loadFileURL method on WKWebView to load the file from the url that we pass to it. We pass the same url to allowReadAccessTo.
This argument will allow the web view to only open that specific file. If we passed a directory as an argument, the web view would only be able to load a file within that directory.
Webview works easily with interface builder, just a single line of code assigning the view to the webview, in iOS or macOS. Our app features context sensitive help so that the appropriate HTML displays in the view the user is in. There are over 80 HTML files so asking the user to exit the app and open another window, etc.
put webView.frame = view.bounds
before view.addSubview(webView)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With