4

I am loading custom HTML in a WKWebView, setting the property width=device-width in the viewport. This works perfectly in iOS 12, but gives a problem with scrolling with iOS 13 (beta 7).

In particular, when width=device-width is used, it is not possible to scroll the webview, so part of the content is not visible. It is only possible to do so if the user pinches to zoom, and then magically it starts to be possible to scroll (both horizontally and vertically).

I didn't find anything in the documentation regarding changes to WKWebView (or even the scrollview) in iOS 13 that could justify this. Am I missing something? Or maybe this is a bug of iOS 13 / Xcode 11?

papafe
  • 2,959
  • 4
  • 41
  • 72

2 Answers2

4

I also encountered this problem because "overflow: hidden" was added to body's style. I deleted "overflow: hidden", and that's all.

lxy_ss
  • 41
  • 1
2

In my case, after reading Insert CSS into loaded HTML in UIWebView / WKWebView I try this:

 func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    insertCSSString(into: webView)
  }

 func insertCSSString(into webView: WKWebView) {
      let cssString = "body { overflow: scroll !important }"
      let jsString = "var style = document.createElement('style'); style.innerHTML = '\(cssString)'; document.head.appendChild(style);"
      webView.evaluateJavaScript(jsString, completionHandler: nil)
  }

Or this:

func insertCSSString(into webView: WKWebView) {
      let jsString = "document.querySelectorAll('*[style]').forEach(el => el.style.overflow = 'scroll');"
    webView.evaluateJavaScript(jsString, completionHandler: nil)
  }

maybe it's helpful.

ArturRuz
  • 49
  • 1
  • 5