1

Is there a way to disable all of the UIPanGestureRecognizers that a touch effects? I am hoping to be able to isolate all touch events to one of my subviews and have every superview ignore all the touch events, but I can only determine this after touchesBegan:withEvent:.

Is it possible to stop my superview's UIPanGestureRecognizers from interacting with a touch after it has triggered touchesBegan:withEvent:?

RileyE
  • 10,874
  • 13
  • 63
  • 106

2 Answers2

2

To disable and re-enable panning in all superviews, you should do something like this:

- (void)recursivelyEnable:(BOOL)enable panGesturesInSuperview:(UIView *)superview
{
    for(UIPanGestureRecognizer *recognizer in superview.gestureRecognizers)
    {
        if([superview isKindOfClass:[UIScrollView class]])[(UIScrollView *)superview setScrollEnabled:enable];
        else [recognizer setEnabled:enable];
    }
    if(superview.superview)[self recursivelyEnable:enable panGesturesInSuperview:superview.superview];
}

and use it like so:

//Disable panning
[self recursivelyEnable:NO panGesturesInSuperview:self.superview];

//Enable panning
[self recursivelyEnable:YES panGesturesInSuperview:self.superview];

For some reason, you can't mess around with the UIGestureRecognizers of a UIScrollView or any of it's subclasses; that is why I've included the check and alternative dis/enabling of panning.

RileyE
  • 10,874
  • 13
  • 63
  • 106
1

Yes use this code:

yourGesture.enabled = NO;
Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70
  • Actually, I was mistaken. It does actually work. I, stupidly, called the wrong method. – RileyE Jul 11 '13 at 23:20
  • Oh. I don't know why I didn't look for an "enabled" property. Let me see if it works after the touch, as well. – RileyE Jul 11 '13 at 23:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33312/discussion-between-rileye-and-abdullah-shafique) – RileyE Jul 11 '13 at 23:33