Multiple gestures for UIGestureRecognizers (iPhone, Cocos2d)

I use Cocos2d to render the sprite and UIGestureRecognizers to allow the user to pan, rotate and scale the sprite.

I work in isolation using the following code:

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 holds his fingers together during rotation (for example, the Photos application). However, unfortunately, the recognizer seems to get stuck in the "rotate" or "pinch" mode and will not simultaneously call both handlers: (

So basically, I want to know - does this mean that I cannot use UIGestureRecognizers? Can I combine two recognizers and perform all the actions in one handler? Should I subclass UIGestureRecognizer to be something like "PinchAndRotateRecognizer".

Help rate :)

+6
source share
2 answers

Just implement gestureRecognizer: shouldRecognizeSimultaneousWithGestureRecognizer: in your deletion.

I have the settings UIPinchGestureRecognizer , a UIPanGestureRecognizer and UIRotationGestureRecognizer , and I want them all to work simultaneously. I also have a UITapGestureRecognizer , which I do not to be recognized at the same time. All I have done is:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] && ![otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { return YES; } return NO; } 
+27
source

Only one gesture recognizer can be โ€œactiveโ€ at a time. The one that starts first wins. This means that you cannot combine UIPinchGestureRecognizer and UIRotationGestureRecognizer to achieve the desired effect.

You can try to subclass UIGestureRecognizer, as you said. Read the subclass notes in the documentation!

-5
source

Source: https://habr.com/ru/post/892894/


All Articles