UIButtons will not work after adding UITapGestureRecognizer

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

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

 [self.view addGestureRecognizer:tap];

My problem is that when I click another UIButton(buttons were created in IB) that are on the same view as UITapGestureRecognizernothing happens.

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

+3
source share
1 answer

try

tap.cancelsTouchesInView = NO;

or

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

All Articles