Ios – How to prevent manual zooming in a UIScrollView

cocoa-touchiosuiscrollview

Hopefully someone can help with this issue. I have a class derived from UIScrollView and I'd like to prevent the user from being able to zoom or scroll via manual pinch and swipe gestures. All view navigation will instead be controlled by programmatic means in response to where a user taps (think of an ebook reader where tapping on the left or right sides of the display causes the view to scroll by exactly one page width). Any suggestions on how to implement this?

Best Answer

On your - (void)viewDidLoad; you should be able to just disable whatever gesture recognizer you want. In this case:

UIPinchGestureRecognizer *pinchRecognizer = self.pinchGestureRecognizer;
pinchRecognizer.enabled = NO;

or

UIPanGestureRecognizer *panRecognizer = self.scrollView.panGestureRecognizer;
panRecognizer.enabled = NO;

I sometimes do this from view controllers that contain UIScrollViews. I just target the scroll view (self.scrollView.pinchGestureRecognizer) and temporarily disable gestures when the app. is in a certain state.