Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely disable magnifying glass for UIWebView iOS9

I've tried the following:

html, body, div, p, a, table, img
{
-webkit-user-select: none !important;
user-select: none !important;
-webkit-user-callout: none !important;
-webkit-touch-callout: none !important;
}

This works for my uiwebview that takes up the whole screen, but for my uiwebview that does not (adbannerview above), it pushes the magnifying glass above the uiwebview over the adbannerview.

Does anyone have any ideas that don't involve disabling UILongPressGestureRecognizers on uiwebview's subviews as suggested in this answer?

like image 861
Mark Avatar asked Sep 21 '15 04:09

Mark


2 Answers

I managed to get suggested comments working by ensuring gestures are disabled after each page load.

So, in your webview delegate:

func webViewDidFinishLoad(webView: UIWebView) {
    disableLongPressGesturesForView(webView)
}

Then your function can look up each subview of the webview (and it's subview children), and disable any long press gestures.

func disableLongPressGesturesForView(view: UIView) {
    for subview in view.subviews {
        if let gestures = subview.gestureRecognizers as [UIGestureRecognizer]! {
            for gesture in gestures {
                if gesture is UILongPressGestureRecognizer {
                    gesture.enabled = false
                }
            }
        }
        disableLongPressGesturesForView(subview)
    }
}
like image 140
rossbeale Avatar answered Sep 28 '22 11:09

rossbeale


I disabled the magnifying glass by iterating the subviews from the webview and finding which has UILongPressGestureRegonizer then disable it

Here is the snippet :

- (void)disableWebViewLongPressGestures:(UIWebView *)webview {
    for(id subView in webview.subviews) {
        if([subView isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scrollView = (UIScrollView *)subView;
            for(id ssView in scrollView.subviews) {
                if([NSStringFromClass([ssView class]) isEqualToString:@"UIWebBrowserView"]) {
                    for(UIGestureRecognizer *gs in [ssView gestureRecognizers]) {
                        if ([gs isKindOfClass:[UILongPressGestureRecognizer class]])
                        {
                            gs.enabled = NO;
                        }
                    }
                }
            }
        }
    }
}
like image 41
Rye Avatar answered Sep 28 '22 11:09

Rye