Context
I have a WKWebView
that I programmatically embed in a UIView
and this UIView
is embedded in a UIScrollView
.
To visualize:
and here is the simplified version of what I have done:
UIScrollView
|
+---- UIView
| |
| +-- UIButton
| |
| +-- UILabel
|
+---- UIView
|
+-- WKWebView
I don't want the WKWebView
to scroll and I have disabled it by injecting the following script on the page.
document.ontouchmove = function(event) { event.preventDefault(); }
The problem
Currently, The scrolling doesn't work when I tapped inside the WKWebView
. But once I tapped back inside the UIView
above, I can scroll again. I've attached a GIF below of what happened. The red section is the WKWebView
and the green section is the UIView
.
What I've done
I have disabled the scrolling using
scrollEnabled
and it doesn't work since I can still scroll theWKWebview
.webView.scrollView.scrollEnabled = false webView.scrollView.bounces = false
Inject the following javascript once the web page is loaded (Current solution)
document.ontouchmove = function(event) { event.preventDefault(); }
Use a static
UITableViewController
for the view, but I still encountered the same problem.