Alessandro
Alessandro

Reputation: 4100

Remove UIGesturerecognizer from UIObject

Is there a way of completely removing all UIGestureRecognisers from any UIObject such as a UItextView? I tried this but it doesn't work:

[photoView removeGestureRecognizer:[photoView.gestureRecognizers objectAtIndex:0]];

NOTE: I don't want to disable them because I would like to assign other gestures recognizers in future.

Upvotes: 0

Views: 1466

Answers (2)

Rob
Rob

Reputation: 437392

If you want to remove all, instead of just:

[photoView removeGestureRecognizer:[photoView.gestureRecognizers objectAtIndex:0]];

You could:

while ([photoView.gestureRecognizers count] > 0)
    [photoView removeGestureRecognizer:[photoView.gestureRecognizers objectAtIndex:0]];

By the way, be aware that some standard text controls will recreate gesture recognizers as you enter and exit editing mode, so you might have to repeat this process accordingly.

Upvotes: 2

Siba Prasad Hota
Siba Prasad Hota

Reputation: 4789

Use the below code to stop any Gesture recognizer.

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {

    // return NO when you want to stop.

if ( [gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]] ) {
        // Return NO for views that don't support Taps
    } else if ( [gestureRecognizer isMemberOfClass:[UISwipeGestureRecognizer class]] ) {
        // Return NO for views that don't support Swipes
    }

    return YES;

}

Upvotes: 0

Related Questions