Vlad Z.
Vlad Z.

Reputation: 3451

UIButtons won't work after UITapGestureRecognizer is added

I have the following code where i add UITapGestureRecognizer to my view:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                      action:@selector(userTapped)];

 [self.view addGestureRecognizer:tap];

My problem is that when I press other UIButtons (buttons were created in IB) that are on the same view as the UITapGestureRecognizer, nothing happens.

I suppose that i add to gestureRecognizer only one action (userTapped:), but how to add interaction with other buttons that were created?

Upvotes: 4

Views: 470

Answers (1)

endy
endy

Reputation: 3872

try

tap.cancelsTouchesInView = NO;

or

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
        if([touch.view isKindOfClass:[UIButton class]])
            return NO;
        return YES;
}

Upvotes: 6

Related Questions