Mapedd
Mapedd

Reputation: 722

UIButton on top of UIView with UITapGestureRecognizer doesn't work

As in the title, I have an UIView sublcass with UITapGR added to it.

In the subclass of this class I'm laying few UIButtons on top of the view. UIButton won't receive any touches. When i tried to see [[tapGR view] class] it was UIButton's parent view. Calling setCancelsTouchesInView to NO won't help either.

Any ideas?

Upvotes: 4

Views: 1263

Answers (2)

dengjiebin
dengjiebin

Reputation: 31

You can use this code to ignore the touch event for the UIButton:

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

Upvotes: 3

Fredrik
Fredrik

Reputation: 1312

If you want to be able to click through something you can

.userInteractionEnabled = NO 

Upvotes: 0

Related Questions