15

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?

Mark
  • 2,666
  • 3
  • 25
  • 29
  • @rmaddy, please read my question. It is not a duplicate of that question. I've tryied their solution and even put their solution in my question and explained what it does. – Mark Sep 21 '15 at 04:38
  • 1
    Same problem here, any solution plz? – Hassan Taleb Sep 25 '15 at 00:14
  • 1
    @HassanTaleb None other than in the answer I posted in my question. As long as you don't mind disabling `UILongPressGestureRecognizers` on all the uiwebview subviews, then you've got a perfectly good solution. The answeree was concerned about Apple rejecting, which is always a concern. I don't think that will be an issue for them. But you never know. – Mark Sep 26 '15 at 02:46
  • 1
    I don't understand "uiwebview subviews", I tried to disable the UILongPressGestureRecognizers in the uiwebview , like this: `let LongTapWebVIew = UILongPressGestureRecognizer()` then: `func LongTapWebViewGesture(){ LongTapWebVIew.addTarget(self, action: "tappedLongWebView") LongTapWebVIew.delegate = self WebView.addGestureRecognizer(LongTapWebVIew) }` then `func tappedLongWebView() { LongTapWebVIew.enabled = false }` then call LongTapWebViewGesture() in viewDidLoad, but the magnifying glass still shown :/.. Can u give me some hint or code plz? @mark – Hassan Taleb Sep 26 '15 at 06:16

2 Answers2

6

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)
    }
}
rossbeale
  • 136
  • 2
  • Can you look at my question here plz @rossbeale? : http://stackoverflow.com/questions/32761868/how-can-we-disable-the-effect-of-enabled-bold-text-from-settings-in-the-iphone/32762352?noredirect=1#comment53389075_32762352 – Hassan Taleb Sep 28 '15 at 16:37
2

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;
                        }
                    }
                }
            }
        }
    }
}
Rye
  • 2,273
  • 9
  • 34
  • 43