How do I make an UIScrollView to ignore single touches?
ios, uiresponder, uiscrollview
Solution
What I have found out: The single-tap event eventually makes its way to `touchesBegan:withEvent:` on the content view inside the inner scroll view. This content view does not implement the method and the default `UIView` implementation passes the event up the responder chain. Here we have the inner scroll view, which does implement `touchesBegan:withEvent:`. This implementation swallows the single tap and nothing goes up the responder chain. What helped is to subclass `UIScrollView` and send the touches up the responder chain manually:
- (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
Of course it’s also good to forward at least `touchesEnded:withEvent:` this way. This does everything I need. The inner scroll view can handle zooming and panning, the outer scroll view receives the single-tap events. I can even zoom in and then pan so far to the right that I go to the next page.
Problem
I have an `UIScrollView` inside another `UIScrollView`. The outer scroll view handles paging, the inner scroll view handles zooming (it’s an image gallery with zooming support). I need the inner scroll view to ignore single touches so that they go to the outer scroll view instead. This can be done using `[innerScrollView setUserInteractionEnabled:NO]`, but that obviously also turns off the pinch and panning gestures on the inner scroll view. Is there a way to keep the pinch and pan gestures handled by the inner zoom view and forward all other events up the responder chain? PS. I can always come with some delegation hack to solve the issue. I’d like to know if there’s a simple way to get it working using the regular responder chain.