Thursday, February 25, 2016

iOS UIWebView disable pinch zoom

In Objective C you can disable pinch zoom in/out option
of a UIWebView Controller just by adding :

webUIView.scalesPageToFit=NO;

But if you turn this property off then the webpage you are trying to show in the UIWebView controller, will be not fit in. There is a way to disable this pinch functionality by keeping this PageFit property turned on. You just need to implement the scrollView property of the WebView Controller.
In the header file you have to add UIScrollViewDelegate.
  webUIView.scalesPageToFit=YES;
  webUIView.scrollView.delegate = self;
 
 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
   return nil;
 }   


Image 1: Adding UIScrollViewDelegate
Image 2: Implementing the Scroll View Delegate of WebViewController
 In Image 1, I am adding Delegate of the UIScrollView in the header file to get delegate methods of scrollview.




In Image 2, I set up the scrollview delegate of webViewController and implement a delegate method of scrollview, viewForZoomingInScrollView, which is returning a nil UIView object to disable the pinch zoom.

No comments:

Post a Comment