Sr.Richie
Sr.Richie

Reputation: 5740

Disabling UIGestureRecognizers in underlying ViewController

In a View Controller I'm building a grid of icons. Each icon opens the same pop-up view , but filled in with different information.

I'm creating the grid in this way:

 for (int i=0; i<NUM_BADGES; i++) {
    BadgeThumbView *thumb = [[BadgeThumbView alloc] initWithFrame:CGRectMake(posX, posY, 70, 100) 
                                                    andWithLabel:[NSString stringWithFormat:@"BADGE NAME N. %d", i]];
    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onBadgeTapped:)];
    [thumb addGestureRecognizer:gestureRecognizer];
    [thumb setTag:i];
    [more code here....]

 }

And in onBadgeTapped method I'm creating the pop up. Now my problem is that everything works fine, but I just realized that when the pop up is opened, while interacting with its buttons I'm still triggering the gesture recognizer in the underlying view controller.

Is there a way to disable all GestureRecognizers in underlying view? Is my strategy wrong? And: is there a way to use a single UIGestureRecognizer for all my icons, in order to disable/enable in a easier way?

Thanks a lot

Upvotes: 0

Views: 337

Answers (2)

Sumanth
Sumanth

Reputation: 4921

I think you should do some thing like disabling the userInteraction for all thumb views when the popup is appearing and re-enabling when disappearing like this

[[yourSuperView subviews]makeObjectsPerformSelector:@selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:FALSE]];

Else add all thumbViews to one subview( say 'b') then add view 'b' to superview(say 'a') as subView and turn off the user interaction to view b when popup appeared and turn on when popup disappears

Upvotes: 0

Max
Max

Reputation: 587

You can remove the recognizer from view or set userInteractionEnabled to temporarily disable it. Depending on how your popup is implemented, you may be able to disable them all at once.

One solution would to be adding thumbs as a subview of a container UIView, and adding that container to your parent view. You could then enable/disable all by setting userInteractionEnabled on the container view.

Upvotes: 1

Related Questions