UIView 顶部的 UIButton 与 UITapGestureRecognizer 不起作用

发布于 2024-12-05 00:30:46 字数 280 浏览 5 评论 0原文

如标题所示,我有一个 UIView 子类,其中添加了 UITapGR

在此类的子类中,我在视图顶部放置了一些 UIButton。 UIButton 不会收到任何触摸。当我尝试查看 [[tapGR view] class] 时,它是 UIButton 的父视图。将 setCancelsTouchesInView 调用为 NO 也无济于事。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏月而来 2024-12-12 00:30:46

您可以使用以下代码忽略 UIButton 的触摸事件:

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

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;
}
谁对谁错谁最难过 2024-12-12 00:30:46

如果您希望能够点击某些内容,您可以

.userInteractionEnabled = NO 

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

.userInteractionEnabled = NO 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文