views:

1570

answers:

2

I have a UIWebview that is loaded as a subview when a user selects a tab on a UISegmentedControl. For some reason, I can not get it to allow pinch/zooming. I set the following code in the viewDidLoad method, so it should work.

self.myWebView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: myWebView];

I tried loading a UIWebView from a NIB and creating it programmatically with no avail. Is there something I'm missing? What could be causing the webview to ignore pinching and zooming?

Thanks!

+1  A: 

I see you are setting the autoresizingMask. Does that mean you have created the UIWebView with an initial size of CGRectZero ? Can you interact with the document at all? I mean, does scrolling/tapping work?

St3fan
I added a piece of the code that I previously left out. I've tried removing the autoresizingMask part with no difference. Yes, everything else works perfectly.
Jonah
What about trying a different web page? To rule out that the page you are testing with has some configuration to disallow pinch/zoom. (This can be influenced by the page)
St3fan
You are correct. I was only loading wikipedia pages and for some reason they don't allow zooming. Any idea why they don't? Thanks!
Jonah
Not totally sure. I think it is done with the `viewport` meta data .. check http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html#//apple_ref/doc/uid/TP40008193-SW1
St3fan
A: 

You have to enable multi-touch. Pinch involves more than one finger on the screen:

[myWebView setMultipleTouchEnabled:YES]

Martin Britz
That was not the problem. Multitouch is enabled by default. There seems to be some sort of code in the wikipedia mobile website that prevented it from zooming in. It works fine on all other sites.
Jonah