0

I have a UIView on some part of screen. This UIView has Pan gesture recognizer. This UIView ( mainVw) has a UITextView that completely covers the UIView. This UITextview has swipe gestures(left and write).

My problem is When I swipe left or right, The UIView starts dragging also. What I want is ,when I drag the UIView it should drag and when I swipe UITextView should swipe left write but no dragging.

Here is the code I'm using to give better understanding:

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [panGesture setMinimumNumberOfTouches:1];
    panGesture.delegate =(id)self;
    [self.mainVw addGestureRecognizer:panGesture];
    //[self.mainVw.layer setValue:[NSValue valueWithCGPoint:vwCaptionBg.center] forKey:@"originalCenter"];


UISwipeGestureRecognizer *rightRecognizer;
rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanTouch:)];
[rightRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];
rightRecognizer.delegate=(id)self;
[self.txtVw addGestureRecognizer:rightRecognizer];


UISwipeGestureRecognizer *vwLeftRecognizer;
vwLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanTouch:)];
[vwLeftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];
vwLeftRecognizer.delegate=(id)self;
[self.txtVw addGestureRecognizer:vwLeftRecognizer];
James Webster
  • 31,873
  • 11
  • 70
  • 114
Sanjay Sharma
  • 151
  • 1
  • 6

1 Answers1

0

You could try using the [GESTURE requireGestureRecognizerToFail:GESTURE_TO_FAIL]; method. This would be your swipes would need to fail before the pan would be allowed to proceed.

There is also delegate methods you can use for simultaneous gestures.

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

Or you could use either of these delegate methods with your own logic.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
Ryan Poolos
  • 18,421
  • 4
  • 65
  • 98