IPhone - conflicts with multiple UIGestureRecognizers

Currently, I have some conflicts with UIGestureRecognizers that make everything work well together. I have several squares (UIView) on the screen that allow the user to pan and pinch (used to scale views). I have a UIPinchGestureRecognizer added to the main view that is added to the squares so that I can scale the square in focus. I also added UIPanGestureRecognizers to each square so that it can be moved around on the screen. The problem appears when I tweak to scale the selected square while my fingers move over the rest. Based on my debugging, it seems that if my tweaking fingers pass through unfocused squares, they eat touches that compensate for the stiffness gesture. Use "[pan requireGestureRecognizerToFail: pinch] "gives priority to the pinch, but creates and gives because the continuous pan recognizer no longer works. I also tried adding a UIPinchRecognizer directly to the square, but which works, but the gesture has a limit on being within the square which does not work if the square is reduced too much. Is there a way around this? Am I missing something?

+5
source share
1 answer

One way to solve your problem is to set a common shared delegate for all your UIGestureRecognizers (probably the UIViewController for this view). This delegate could return NO for gestureRecognizerShouldBegin: (UIGestureRecognizer *) gestureRecognizer if the hard drive gesture recognizer was in the Start or Modified state (this meant that it recognized and processed the pinch). This should prevent any of the draw recognizers from eating touch during gestures.

In the interface file, you will need to save the link to the gesture recognizer when pressed:

@interface MyViewController : UIViewController <UIGestureRecognizerDelegate> {
  UIGestureRecognizer *pinchGestureRecognizer;
}

, , :

@implementation MyViewController

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
  if(pinchGestureRecognizer.state == UIGestureRecognizerStateBegan ||
     pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) 
  {
    return NO;
  }
  else
  {
    return YES;
  }
}
+3

All Articles