How to prevent manual zooming in a UIScrollView?

To prevent user-controller zooming and panning but still allow programmatic zooming and panning of a scrollview, the best approach is to override the UIScrollView's -addGestureRecognizer: method in a subclass. In my use I wanted to block all the recognizers and control the viewable area completely from my view controller, I did so like this.

Up vote 1 down vote favorite share g+ share fb share tw.

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? Cocoa-touch ios uiscrollview link|improve this question asked Jan 16 '11 at 9:07Shinohara866.

To prevent user-controller zooming and panning but still allow programmatic zooming and panning of a scrollview, the best approach is to override the UIScrollView's -addGestureRecognizer: method in a subclass. In my use I wanted to block all the recognizers and control the viewable area completely from my view controller, I did so like this: -(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { //Prevent any of the default panning and zooming controls from working gestureRecognizer. Enabled = NO; super addGestureRecognizer:gestureRecognizer; } Each gesture recognizer is simply disabled, for finer control (allowing the pan control but only allow zooming via a double tap for instance) you'd simply check the incoming gesture recognizer via -isKindOfClass: and disabling as appropriate.

-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { //Prevent zooming but not panning if (gestureRecognizer isKindOfClass:UIPinchGestureRecognizer class) { gestureRecognizer. Enabled = NO; } super addGestureRecognizer:gestureRecognizer; } I used this method in a comic reading app that uses guided navigation to animate between cropped panels on a page with the full page being contained in a UIScrollView. I can smoothly zoom in and out on a selected area by simply setting the view bounds to the region I want to display.

I don't have too much experience with UIScrollViews, but looking at the docs, it looks like you can set maximumZoomScale, minimumZoomScale, and scrollEnabled to disable everything you want to disable. Here are the docs: developer.apple.com/library/ios/#documen... From the docs: scrollEnabled: If the value of this property is YES , scrolling is enabled, and if it is NO , scrolling is disabled. The default is YES.

When scrolling is disabled, the scroll view does not accept touch events; it forwards them up the responder chain. MaximumZoomScale: This value determines how large the content can be scaled. It must be greater than the minimum zoom scale for zooming to be enabled.

The default value is 1.0.

I ended up discovering this is best done by subclassing the scrollview, and replacing the method that attaches a Gesture Recognizer to the view. By intercepting this you can check the class of the gesture recognizer being attached and block the pinch and pan gesture recognizers. For the code I was writing I wanted to prevent the usual pinch and pan gestures from working so that navigation was exclusively under programmatic control.

I simple set the inherited subclass to never attach gesture recognizers and then my code acted on touch events received by the subview of the scrollview. – Shinohara Mar 19 '11 at 5:54 did you have an example of this code? Thanks!

– Ben Novakovic Jun 16 '11 at 0:27.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions