开发者

UIButton on top of UIView with UITapGestureRecognizer doesn't work

开发者 https://www.devze.com 2023-04-05 05:14 出处:网络
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 s

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?


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;
}


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

.userInteractionEnabled = NO 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号