Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the magnifying glass in UIWebview?

How can I disable the magnifying glass that appears when you hold the touch on a UIWebView? I don't want to to disable user interaction but I don't want the webview to show that zoom glass. Any Ideas?

like image 860
Mashhadi Avatar asked Aug 23 '11 06:08

Mashhadi


4 Answers

I have found that -webkit-user-select: none; alone doesn't do the trick. Instead I have found a quite undocumented property -webkit-touch-callout

What I usually do with Phonegap apps is this:

body, body * {
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-user-callout: none !important;
    -webkit-touch-callout: none !important;
}
input, textarea {
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-user-callout: default !important;
    -webkit-touch-callout: default !important;
}

Somewhere it was mentioned that -webkit-user-callout is a legacy version of -webkit-touch-callback, I have put this in just in case.

like image 121
Rob Fox Avatar answered Sep 30 '22 10:09

Rob Fox


No, the loupe is inextricably linked to selection. To disable it, you will have to disable selection entirely (you can use -webkit-user-select: none to do that).

like image 28
jtbandes Avatar answered Oct 23 '22 01:10

jtbandes


Because the accepted solution did not work for me, I had to look for other options and I found one.
Note that I don't know if Apple approves this technique. Use it at your own fear and risk.

(Ours wasn't rejected; I don't think Apple cares that much about you messing with UIWebView internals, but be warned.)

What I did was recursively walk down UIWebView subviews and enumerate their gestureRecognizers. Whenever I encounter a UILongPressGestureRecognizer, I set its enabled to NO.

This gets rid of the magnifying glass altogether and obviously disables any default long-press functionality.

It seems like iOS re-enables (or re-creates) these gesture recognizers whenever user begins to edit text.
Well, I don't mind using magnifying glass in text fields so I don't disable them immediately.

Instead, I wait for blur event on my text elements, and when it occurs, I walk the subview tree again.
Simple as that, and it works.

like image 7
Dan Abramov Avatar answered Oct 23 '22 02:10

Dan Abramov


Because I don't know how to use -webkit-user-select: none I looked for other ways. And I stumble into this Customize the contextual menu of UIWebView then I combined it with -webkit-user-select: none.

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
   [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];
}
like image 3
jovhenni19 Avatar answered Oct 23 '22 01:10

jovhenni19