0

I have made a simple web browser for the iPhone but I would really like to be able to pinch to zoom in and out with the UIPinchGestureRecognizer, but I don't know how to use it. Could someone explain to me how to implement it in my code? If you have a link to a good explanation of this that would be very much appreciated as well.

Adam U.
  • 133
  • 1
  • 1
  • 6

2 Answers2

0

Why do you need to implement it at all? UIWebView already supports pinch-zooming natively.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • Really? hmmm... when I built the app to my iPhone it wouldn't let me pinch at all. It wouldn't be that big of a deal if it formatted the whole page, but it zoomed in to a small square of the page and it is quite hard to do anything. – Adam U. Aug 04 '11 at 21:13
  • The page itself can disable pinch-zooming through the use of a particular `` tag, but if it hasn't done that, then UIWebView should behave very similarly to how Safari behaves. – Lily Ballard Aug 04 '11 at 21:33
  • Ok, thanks! the site has: `` and some ``. Thanks for the info! – Adam U. Aug 04 '11 at 21:53
  • Try navigating your custom browser to Amazon.com and seeing if you can zoom their. You should be able to. – Benjamin Mayo Aug 04 '11 at 22:20
  • @Adam The meta tag in question looks like ``. The important bit here is the name `"viewport"` and the content value `user-scalable=no`. This is what prevents pinch-resizing on iOS. However, this meta tag also affects MobileSafari, so if you can't pinch-resize in your `UIWebView` then you shouldn't be able to do so from MobileSafari either. – Lily Ballard Aug 04 '11 at 22:43
  • Thanks for all of the information! I figured out the problem (really dumb mistake...). I forgot to check "Scales to fit page" for the UIWebView. It didn't pinch for amazon so I figured I did something wrong. Sorry about that and thanks for the help! =] – Adam U. Aug 05 '11 at 15:37
0

For all the stuff you need for gesture recognizer's, look here. Basically, you set up a gesture for your view, and add a selector method that would get called if the view recognizes that gesture. In this case, when it detects a pinch, you would tell the view to change size to your liking.

This, however, is the hard way of doing it though, as the pinch gesture is already associated with a UIWebView (not to mention, the MKMapView as well). You should probably look at this other post to see what you need to do. Any search on google will also point you in the right direction. Hope that helps!

Community
  • 1
  • 1
msgambel
  • 7,320
  • 4
  • 46
  • 62