Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView disable zooming when scalesPageToFit is ON

Tags:

Is there any way to disable zooming when Scales page to Fit is ON ??

like image 378
Jim Avatar asked Jan 30 '12 10:01

Jim


2 Answers

This works for me:

UIScrollView *scrollView = [webView.subviews objectAtIndex:0];
scrollView.delegate = self;//self must be UIScrollViewDelegate

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  return nil;
}

UPDATE: For iOS 5 or higher get scrollView like this:

webview.scrollView.delegate = self;
like image 125
protuberian Avatar answered Sep 25 '22 03:09

protuberian


Instead of using

UIScrollView *scrollView = [webView.subviews objectAtIndex:0];
scrollView.delegate = self;//self must be UIScrollViewDelegate

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return nil;
}

You can use this:

webview.scrollView.delegate = self;

-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {
return nil;
}

Second option is better and full-proof. First logic could fail in future SDKs.

like image 31
Rishabh Tayal Avatar answered Sep 22 '22 03:09

Rishabh Tayal