Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UIWebView Zoom/Pinch

rramnelrramnel Posts: 35Registered Users
edited July 2011 in iOS SDK Development
Hello,

I am loading a webpage inside a UIWebView. But I am unable to zoom/pinch. Is zooming functionality already built in inside the UIWebView class? Or do I need to setup a UIScrollView and setup the UIWebView inside it? Any ideas on how to proceed...
Post edited by rramnel on
· ·

Replies

  • JeromeCJeromeC Posts: 60Registered Users
    edited February 2009
    did you check that the checkbox "User Interaction Enabled" is checked on the Attributes inspector ?

    If you haven't, click on the view and select tools/Inspector and check that. Sometimes it comes deactivated depending on what template you used.
    <div align="center"><img src="http://www.iphonedevsdk.com/forum/images/smilies/confused.gif" border="0" alt="" title="Confused" class="inlineimg" /> <img src="http://www.iphonedevsdk.com/forum/images/smilies/frown.gif" border="0" alt="" title="Sad" class=
    · ·
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited February 2009
    rramnel wrote: »
    Hello,

    I am loading a webpage inside a UIWebView. But I am unable to zoom/pinch. Is zooming functionality already built in inside the UIWebView class? Or do I need to setup a UIScrollView and setup the UIWebView inside it? Any ideas on how to proceed...

    Are you configuring the properties for the webview. If not you need to set its contentSize, minimumZoomScale, maximumZoomScale etc.

    check the doco for these and it should help.

    m.
    · ·
  • ziconicziconic Posts: 64Registered Users
    edited February 2009
    Also check that the webpage you are trying to display has zooming enabled. Apple has some proprietary html meta tags that you can use to disable zooming, e.g. if your website is built specifically for the iPhone.
    <a href="http://www.storieapp.com" target="_blank">Storie</a><br />
    <font size="1"><a href="http://itunes.apple.com/us/app/storie/id460389012?mt=8" target="_blank">Download Storie now</a> - it's free!</font>
    · ·
  • rramnelrramnel Posts: 35Registered Users
    edited February 2009
    Thank you all for the replies. I managed to solve the problem. The problem was that I was not implementing the UIWebViewDelegate. Once I implemented this, everything worked like a charm :)
    · ·
  • needbloodneedblood Posts: 1New Users
    edited May 2010
    rramnel, can you give me an example code how did you solve the problem? Thanks much.
    · ·
  • spoolupspoolup Posts: 97Registered Users @
    edited September 2010
    can this function be done selectively?
    ie. diable pinch/zoom for one of the pages loaded? and leave it active for the rest?
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited September 2010
    spoolup wrote: »
    can this function be done selectively?
    ie. diable pinch/zoom for one of the pages loaded? and leave it active for the rest?

    yes, you can look which page is loaded, maybe with
    – webView:shouldStartLoadWithRequest:navigationType:

    and then disable gestures if it is on the page that you like.

    to disable gestures i think that you can subclass uiwebview, as explained here:
    Hacking UIScrollView Gesture Recognizers @ Dr. Touch
    · ·
  • fnicolafnicola Posts: 2New Users
    edited December 2010
    maybe i can help you..

    it works for me

    UIWebView *web = ...
    ..
    .
    .
    
    //set zoom here
    UIScrollView *sv = [web.subviews objectAtIndex:0];
    [sv setZoomScale:0.0 animated:YES];
    

    salute,
    F
    · ·
  • DarkinDarkin Posts: 23Registered Users
    edited February 2011
    rramnel wrote: »
    Hello,

    I am loading a webpage inside a UIWebView. But I am unable to zoom/pinch. Is zooming functionality already built in inside the UIWebView class? Or do I need to setup a UIScrollView and setup the UIWebView inside it? Any ideas on how to proceed...

    Make sure to have the UIWebView Selected on interface builder and then enable "Scale to fit" at the very top of the list of properties. The pinch and zoom should work after that. Might also want to make sure that "multiple touches" is also enabled both on the UIWebView and the main UIView.
    · ·
  • abc123miguelabc123miguel Posts: 13Registered Users
    edited July 2011
    Darkin wrote: »
    Make sure to have the UIWebView Selected on interface builder and then enable "Scale to fit" at the very top of the list of properties. The pinch and zoom should work after that. Might also want to make sure that "multiple touches" is also enabled both on the UIWebView and the main UIView.

    This last answer seems to be the easiest way to do it. You can do it programmatically by

    [webView setScalesPageToFit:YES];

    Only problem is text can be very small. Setting Scale on UIScrollview subview results in larger text but blurry. Refocuses once you zoom/pinch.
    · ·
Sign In or Register to comment.