I start with a simple application that simply displays a web view using WKWebView. Everything builds and works fine, except that it is always full-screen mode. Ideally, this does not apply to the iOS status bar at the top. It must be lowered by 20 pixels to be below it. I searched extensively for a solution, but nothing resizes. Nothing is configured in InterfaceBuilder, I do everything programmatically. Using Swift
This is similar to what many applications with WKWebView will do. It should be easy. I probably missed something obvious. Any help is appreciated. Thanks in advance.
This is what I have so far:
import UIKit import WebKit class ViewController: UIViewController, UIGestureRecognizerDelegate , UIWebViewDelegate, WKNavigationDelegate { let url = NSURL(string:"http://stackoverflow.com") var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() webView = WKWebView(frame: CGRect( x: 0, y: 20, width: 380, height: 150 ), configuration: WKWebViewConfiguration() ) self.view = webView self.view.frame = webView.frame let req = NSURLRequest(URL:url!) webView.loadRequest(req) self.webView.allowsBackForwardNavigationGestures = true } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
Thanks a lot Emilio! The configured code works great!
import UIKit import WebKit class ViewController: UIViewController, UIGestureRecognizerDelegate , UIWebViewDelegate, WKNavigationDelegate { let url = NSURL(string:"http://stackoverflow.com") var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() webView = WKWebView(frame: CGRect( x: 0, y: 20, width: self.view.frame.width, height: self.view.frame.height - 20 ), configuration: WKWebViewConfiguration() ) self.view.addSubview(webView) let req = NSURLRequest(URL:url!) webView.loadRequest(req) self.webView.allowsBackForwardNavigationGestures = true } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
Eddie source share