Adam
Adam

Reputation: 733

Scroll view panning prevents pinch gesture?

I'm creating an image tiling library for use in a game project, to fit into our existing framework. I'm currently using a UIScrollView (with an empty view) to allow me to hijack the nice physics for panning around with bounce, but I had to implement my own zoom using the pinch gesture recogniser (for reasons I won't get into).

Here's the thing, though - when I'm panning with one finger, adding a second touch and trying to zoom does nothing. I need to be absolutely still before it will allow me to zoom. When the user is panning around the image, my pinch gesture recogniser never fires unless the pan has totally finished.

Does anyone know a way around this, that doesn't involve scrapping the UIScrollView and implementing my own pan as well?

Here's my scrollViewDidScroll function:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    viewingBounds.origin.x = scrollView.contentOffset.x;
    // Transform the y from UIKit coordinates into OpenGL coordinates
    viewingBounds.origin.y = world.height - viewingBounds.size.height - scrollView.contentOffset.y;
    [parentScene update]; // Render the image
}

My gesture recogniser is added directly to the scroll view in init:

[scrollView addGestureRecognizer:[[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(didReceivePinch:)] autorelease]];

Upvotes: 3

Views: 1600

Answers (3)

Asad R.
Asad R.

Reputation: 1051

You need to set the delegate of your GestureRecognizer objects, and in the delegate implement this method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

And have it return YES.

Upvotes: 1

Tremaine
Tremaine

Reputation: 55

Hey Adam, I don't know if you have rewritten anything yet but I have some alternatives for you here, here, here, worse case ask someone the same question here. Hope that helps.

Upvotes: 0

Tremaine
Tremaine

Reputation: 55

Have you tried anything from Apple's ZoomingPDFViewer or PhotoScroller? In Photo Scroller the images are tiled and tile and you zoom in. Hopefully there is something you can get out of it. If you have trouble unzipping the file try downloading from Xcode.

I think I also found a few other people doing something close:

https://stackoverflow.com/questions/5383757/scaling-panning-a-uiimageview-using-pinch-and-swipe-gestures-free-code

http://answers.unity3d.com/questions/22500/how-to-zoom-and-pan-when-you-pinchswipe-across-scr.html

http://technology.blurst.com/iphone-multi-touch/

Hope it helps.

Upvotes: 0

Related Questions