I’m using Cocos2d to render a sprite, and UIGestureRecognizers to allow the user to Pan, Rotate and Scale the sprite.
I’ve got each working in isolation using code like the following:
UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePinchFrom:)] autorelease];
[viewController.view addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:layer action:@selector(handleRotationFrom:)] autorelease];
[viewController.view addGestureRecognizer:rotationRecognizer];
However, I want to both scale and rotate the sprite if the user pinches their fingers together whilst rotating (the Photos app does this, for instance). Unfortunately though, the recognizer seems to get stuck in either “rotate” or “pinch” mode, and won’t call both handlers at the same time 🙁
So, basically, I want to know – does this mean I can’t use UIGestureRecognizers? Can I combine two recognizers and do all of the actions in a single handler? Will I have to subclass UIGestureRecognizer to be something like “PinchAndRotateRecognizer”.
Help appreciated 🙂
Just implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in your delegate.
I have a
UIPinchGestureRecognizer, aUIPanGestureRecognizerand aUIRotationGestureRecognizerset up and I want them all to work at the same time. I also have aUITapGestureRecognizerwhich I do not want to be recognized simultaneously. All I did was this: