我正在使用按预期工作的WkWebView。但是当我旋转设备时,WkWebView正在扩展到屏幕尺寸,但webview内的内容没有调整大小。
我见过其他帖子: WKWebView added as Subview is not resized on rotation in Swift
我正在使用
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
正如许多其他人所建议但似乎没有任何效果。
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
let config = WKWebViewConfiguration()
config.processPool = GlobalVariables.myWebPool
let contentController = WKUserContentController()
config.userContentController = contentController
contentController.add(self, name: "appInterface")
webView = WKWebView(frame: webContainer.bounds, configuration: config)
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
if let theWebView = webView{
let urlString = "https:www.xyz"
let myUrl = URL(string: urlString)
myRequest = URLRequest(url: myUrl!)
setCookie(key: "ASP.NET_SessionId", value:GlobalVariables.cookieValue)
theWebView.navigationDelegate = self
webContainer.addSubview(theWebView)
self.webView?.load(self.myRequest)
}
}