Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the double-tap event in UIWebView

I'm building a custom web app and one feature that keeps getting in the way is the "double-tap-to-zoom" on the UIWebView. I've looked on this forum and the web and I don't see an obvious way to disable this.

How can I disable or ignore double-tap-to-zoom in my app?

like image 469
C4W Avatar asked Jul 10 '15 14:07

C4W


3 Answers

You simply can disable zooming with putting this code in your viewDidLoad Method:

myWebView.scalesPageToFit = NO;

There is another approach for this. Add this meta tag to the head section of your webView contents:

<meta name="viewport" content="user-scalable=0">
like image 137
hmak.me Avatar answered Nov 05 '22 18:11

hmak.me


Craig : yo are doing a web app... your code is HTML/Css/Js, I guess.

Solution: use this in <head></head>

<meta name="viewport" content="user-scalable=0">

Advice You would win if you learn about meta viewport option. Very useful when doing web app for mobiles. Particularly Apple ones.

like image 5
3pic Avatar answered Nov 05 '22 18:11

3pic


First option - You can disabled double tap and pinch to zoop by setting this.

_webView.scalesPageToFit = NO;
_webView.multipleTouchEnabled = NO;

Second Option - You can execute the following piece of code in webViewDidFinishLoad to prevent double tap - zoom

NSString *js = @"var metaTag=document.createElement('meta');"
"metaTag.name = \"viewport\";"
"metaTag.content = \"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\";"
"document.getElementsByTagName('head')[0].appendChild(metaTag);";
[webView stringByEvaluatingJavaScriptFromString:js];
like image 2
Subbu Avatar answered Nov 05 '22 18:11

Subbu