Search code examples
iosobjective-cuiimageviewuigesturerecognizeruipagecontrol

Disable Gesture Recognizer for UIImageView in iPad app


I have a PageControl and each page (ViewController) has different number of imageviews (UIImageView), which are created dynamically.

Each imageview is assigned a gesture recognizer (tapped or move). Since these are inside a PageControl, I would like to enable/disable the gesture recognizer so it won't interfere with the swipe to page events.

I know that there's a removeGestureRecognizer method, but I don't want to remove and attach that each time. Is there an equivalent for just enabling and disabling?

Thanks


Solution

  • You can use enable or disable properties of the UIGestureRecognizer like :

    swipeGestureRecognizer.enabled = NO;
    

    or you can use the gesture recognizer method return null if you don't want touches

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