1

I am using WkWebView which works as expected. But when I rotate the device WkWebView is expanding to the screen size but the content inside the webview is not resizing.

I have seen other posts like : WKWebView added as Subview is not resized on rotation in Swift

I am using

webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

as many others suggested but nothing seems to work.

Here is my code:

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)
    }
}
Sindhu
  • 421
  • 1
  • 6
  • 16

0 Answers0