tylercasson
tylercasson

Reputation: 56

UIPanGestureRecognizer overlaps UISwipeGestureRecognizer

I have a UIView with a UIPanGestureRecognizer attached to it. I also have an object within the UIView that has multiple UISwipeGestureRecognizers.

The UIPanGestureRecognizer and the UISwipeGestureRecognizers associated with the object overlap.

Is there any way to make the UIPanGestureRecognizer totally ignore a certain area of the UIView or make the object's UISwipeGestureRecognizers take precedence and override the UIView's UIPanGestureRecognizer?

Upvotes: 2

Views: 2302

Answers (3)

Shefy Gur-ary
Shefy Gur-ary

Reputation: 658

Thanks a lot for the answers, which helped me with my issue.

I just want to share my solution, because it can be helpful:

-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog2(@"Gesture on Class %@ tag %i", [touch.view class], touch.view.tag);////////

if (touch.view.tag == kTagToIgnoreGestures){
    return NO;
}
return YES;

}

I defined a kTagToIgnoreGestures which is tag of views that should ignore gestures. This way I can have 2 subviews in a view with UIGestureRecognizer, that only one of them will be effected by gestures.

Hope it helps. Shefy

Upvotes: 1

tylercasson
tylercasson

Reputation: 56

Solved this problem using this delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
      if ([touch.view isKindOfClass:[UIButton class]] && gestureRecognizer == recognizer) return NO;
      return YES;
}

Thanks for pointing me in the right direction @MikeS

Upvotes: 2

MikeS
MikeS

Reputation: 3921

What you want is...

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
     if(gestureRecognizer == myPanGesture) return NO;

     return YES;
}

Or a similar usage of that delegate method. It is part of the UIGestureRecognizerDelegate protocol. This would allow you to not recognize the panning if you are swiping.

Upvotes: 4

Related Questions