Turn off Zooming in UIScrollView

CodingWithoutComments picture CodingWithoutComments · Oct 13, 2009 · Viewed 23.3k times · Source

Does anyone know a way to temporarily turn off zooming when using a UIScrollView?

I see that you can disable scrolling using the following:

self.scrollView.scrollEnabled = false;

but I'm not seeing a similar command for zooming. Any thoughts?

Answer

combinatorial picture combinatorial · Dec 19, 2013

If you want to disable the user's ability to zoom through gestures then in iOS 5 and above you can disable the pinch gesture. This still allows you to control the scroll view from code...

scrollView.pinchGestureRecognizer.enabled = NO;

similarly for pan...

scrollView.panGestureRecognizer.enabled = NO;

This must be called in - (void)viewDidAppear:(BOOL)animated or later as otherwise the system resets it to enabled.

Swift 4.x and above:

imageZoomView.pinchGestureRecognizer?.isEnabled = false / true