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 :)
Gesture recognition is technology that uses sensors to read and interpret hand movements as commands. In the automotive industry, this capability allows drivers and passengers to interact with the vehicle — usually to control the infotainment system without touching any buttons or screens.
There are seven type of gesture that support in ios .
A pan gesture occurs any time a person moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.
UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer . For gesture recognition, the specified number of fingers must tap the view a specified number of times. Although taps are discrete gestures, they're discrete for each state of the gesture recognizer.
Just implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in your delegate.
I have a UIPinchGestureRecognizer
, a UIPanGestureRecognizer
and a UIRotationGestureRecognizer
set up and I want them all to work at the same time. I also have a UITapGestureRecognizer
which I do not want to be recognized simultaneously. All I did was this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] && ![otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
return YES;
}
return NO;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With