Disable double-click scrolling on WKWebView

I have a custom keyboard with WKWebView in full width and height. I disabled scrolling through wkWebView!.scrollView.scrollEnabled = false, but I still have weird double-tap scrolling behavior at the bottom of WKWebView. Here is the source code of a simple webpage I'm trying to download: http://is.gd/gt8h2q (very simple, just a full screen div with a green background and one line of text). Below, GIF as an explanation. This is how I create WKWebView:

class KeyboardViewController: UIInputViewController, WKScriptMessageHandler {
var wkWebView: WKWebView?

override func loadView() {
    super.loadView()

    let contentController = WKUserContentController()
    contentController.addScriptMessageHandler(self, name:"callbackTestOne")

    let config = WKWebViewConfiguration()
    config.userContentController = contentController

    self.wkWebView = WKWebView(frame:self.view.frame, configuration:config)
    self.view = self.wkWebView!
}

override func viewDidLoad() {
    super.viewDidLoad()

    (...)

    wkWebView!.scrollView.bounces = false
    wkWebView!.scrollView.scrollEnabled = false
    wkWebView!.scrollView.backgroundColor = UIColor(red:248, green:248, blue:248, alpha:1)
    wkWebView!.scrollView.opaque = true
    wkWebView!.scrollView.showsHorizontalScrollIndicator = false
    wkWebView!.scrollView.showsVerticalScrollIndicator = false
    wkWebView!.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal
}

(...)

GIF Explanation

+4
source share
3 answers

, . , UITapGestureRecognizer, .

WKWebView, , , UIScrollView , WKWebView, . , , .

webView, . :

// iterate over all subviews of the WKWebView scrollView
for subview in _webView.scrollView.subviews {

    // iterate over recognizers of subview
    for recognizer in subview.gestureRecognizers ?? [] {

        // check the recognizer is  a UITapGestureRecognizer
        if recognizer.isKind(of: UITapGestureRecognizer.self) {

            // cast the UIGestureRecognizer as UITapGestureRecognizer
            let tapRecognizer = recognizer as! UITapGestureRecognizer

            // check if it is a 1-finger double-tap
            if tapRecognizer.numberOfTapsRequired == 2 && tapRecognizer.numberOfTouchesRequired == 1 {

                // remove the recognizer
                subview.removeGestureRecognizer(recognizer)
            }
        }
    }
}

.

+6

. , , . UITapGestureRecognizer , WKWebView, UIViewController . :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if ([[otherGestureRecognizer description] containsString:@"WKSyntheticClickTapGestureRecognizer"] && [[otherGestureRecognizer description] containsString:@"numberOfTapsRequired = 2"]) {
        [otherGestureRecognizer removeTarget:nil action:nil];
        return YES;
    }

1 , . , . - , - WKWebView .   WKSelectionGranularityCharacter WKWebViewConfiguration - , (Apple, ?) , iOS8 - , , . iOS9 - http://www.openradar.me/23345435 . .

+4

, , WKWebView, . .

:

<meta id="viewport" name="viewport"
    content="width=device-width; user-scalable=false" />
-1

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


All Articles