Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should use javascript in the UIWebView to detect the gestures. (You can then communicate that back to the Objective-C if you need to.) These are <a href="https://developer.apple.com/iphone/iad/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html" rel="nofollow noreferrer">Apple's docs</a> on detecting gestures and touches in Javascript. I also found this <a href="http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/" rel="nofollow noreferrer">article</a> helpful, although he uses a javascript library to deal with event binding, etc.</p> <p>Here's a working example of pinching to zoom on a UIWebView that stands alone.</p> <p><em>Note that it is the body element is listening for the event. On a short page it appears not to catch it if you do the event in the vast un-rendered whitespace below. (If anyone knows more about it, please leave a comment.)</em></p> <pre><code>&lt;body id='body'&gt; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco &lt;script type="text/javascript" charset="utf-8"&gt; body = document.getElementById('body'); // (in percents) zoom = 100; maxZoom = 200; minZoom = 50; zoomIncrement = 25; function gestureEnd(event) { var newZoom; if (event.scale &gt; 1.0) { // increase size newZoom = zoom + zoomIncrement; } else { // decrease size newZoom = zoom - zoomIncrement; } // don't exceed zoom boundaries if (newZoom &gt; maxZoom || newZoom &lt; minZoom) { return; } zoom = newZoom; body.style.webkitTextSizeAdjust = zoom+"%"; } body.addEventListener("gestureend", gestureEnd, false); &lt;/script&gt; &lt;/body&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload