iosuiscrollviewzoomingmulti-touchpanning

Paging UIScrollView with two-finger pan and zoom


The test case is easily reproduced: download Apple's PhotoScroller sample app, and try to adapt it so that panning (both around a zoomed image, and between each image) only works with two fingers.

Setting the panGestureRecognizer for both the pagingScrollView and the imageScrollView to only accept a min & max of 2 touches seems like a good place to start, however it doesn't work. It lets you scroll around an image with two fingers just fine*, however paging then doesn't work.

I've tried so many combinations of settings and custom gesture recognizers, and I'm a bit stumped. Is a custom scroll view subclass going to be of any use, or can I somehow manipulate the scroll view delegate methods to make it work?

*EDIT: Actually, it doesn't scroll fine in this situation. The view no longer glides smoothly as with a single touch...

UPDATE: I'm still struggling with this one. I would appreciate some input from somebody who has played around with UIGestureRecognizers and UIScrollViews.

EDIT:

Setting the ImageScrollView class to only accept two touches:

- (id)initWithFrame:(CGRect)frame
{
    // ...
    // Template code
    // ...

    [self.panGestureRecognizer setMinimumNumberOfTouches:2];
    [self.panGestureRecognizer setMaximumNumberOfTouches:2];
}

Setting PhotoViewController's pagingScrollView to only accept two touches:

- (void)loadView
{
    // ...
    // Template code
    // ...

    [pagingScrollView.panGestureRecognizer setMinimumNumberOfTouches:2];
    [pagingScrollView.panGestureRecognizer setMaximumNumberOfTouches:2];
}

These modifications are made directly on top of the PhotoScroller sample app. I would expect these simple changes to work for two-finger interaction, however the side-effects are odd (as explained above).


Solution

  • It would appear that this is either impossible, or very very difficult (i.e. roll your own scroll view from scratch). I used an Apple Tech support incident and they were unable to help. If a solution becomes available I'll happily mark it as the accepted answer!