WKWebView inside UIScrollView: scrolling conflict

Context

I have WKWebViewone that I programmatically embed in UIView, and this one UIViewis built in UIScrollView.

To visualize:

Scene View Hierarchy

and here is a simplified version of what I did:

UIScrollView
|
+---- UIView
|    |
|    +-- UIButton
|    |
|    +-- UILabel
|
+---- UIView
     |
     +-- WKWebView

I don't want to scroll WKWebView, and I turned it off by entering the following script page on the page.

document.ontouchmove = function(event) { event.preventDefault(); }



Problem

Currently, scrolling does not work when I entered WKWebView. But as soon as I slammed back to UIViewabove, I can scroll again. I added a GIF below what happened. The red section is WKWebView, and the green is UIView.


Scroll problem



What I've done

  • I disabled scrolling with scrollEnabledand it doesn’t work as I can still scroll WKWebView.

    webView.scrollView.scrollEnabled = false
    webView.scrollView.bounces = false
    
  • javascript - ( )

    document.ontouchmove = function(event) { event.preventDefault(); }
    
  • UITableViewController , .


:

+5
1

. ScrollView ScrollView :

scrollView.contentInset = UIEdgeInsetsMake(FLT_EPSILON, FLT_EPSILON, FLT_EPSILON, FLT_EPSILON);

, WKWebview , scrollView , scrollview. FLT_EPSILON WkWebView .

WKWebView UIScrollView. UIScrollView UIScrollView .

0

Source: https://habr.com/ru/post/1656655/


All Articles