Tuesday, November 10, 2026
HomeiOS Developmentios - WKWebView UI breaks when web page is scrolled and revisited...

ios – WKWebView UI breaks when web page is scrolled and revisited once more

[ad_1]

We’re utilizing WkWebView for our IOS APP. When person scrolls the webpage, goes to a different web page and revisits once more the web page UI breaks or typically goes clean. However when once more began scrolling, UI restores. Tips on how to repair this? Following is the code

func createWebView(container: UIView, WKSMH: WKScriptMessageHandler, WKND: WKNavigationDelegate, NSO: NSObject, VC: ViewController) -> WKWebView{
    
    let config = WKWebViewConfiguration()
    let userContentController = WKUserContentController()

    userContentController.add(WKSMH, title: "setUserAttribute")
    userContentController.add(WKSMH, title: "print")
    config.userContentController = userContentController
    if #obtainable(iOS 14, *) {
        config.limitsNavigationsToAppBoundDomains = true;
    }
    config.preferences.javaScriptCanOpenWindowsAutomatically = true
    config.allowsInlineMediaPlayback = true
    config.preferences.setValue(true, forKey: "standalone")
    
    let webView = WKWebView(body: calcWebviewFrame(webviewView: container, toolbarView: nil), configuration: config)
    setCustomCookie(webView: webView)
    webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    webView.isHidden = true;
    webView.navigationDelegate = WKND;
    webView.scrollView.bounces = false;
    webView.allowsBackForwardNavigationGestures = true
    webView.configuration.applicationNameForUserAgent = "Safari/604.1" // See https://github.com/pwa-builder/pwabuilder-ios/points/30
    webView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Model/15.0 Cell/15E148 Safari/604.1";
    if #obtainable(iOS 11.0, *) {
        webView.scrollView.contentInsetAdjustmentBehavior = .by no means
    } else {
        // Fallback on earlier variations
    }
    webView.addObserver(NSO, forKeyPath: #keyPath(WKWebView.estimatedProgress), choices: NSKeyValueObservingOptions.new, context: nil)
    
    return webView
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments