質問

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:?

役に立ちましたか?

解決

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.

他のヒント

Yes use this code:

yourGesture.enabled = NO;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top