【iOS】为什么在Category中创建的UIView的点击事件无效

发布于 2022-08-30 00:50:16 字数 945 浏览 14 评论 0

我们工程中为了实现应用内的消息通知,所以新建了Category来响应推送通知,并提示用户。但是当消息框弹出时,虽然给UIView加上了UITapGestureRecognizer,同时也设置了setUserInteractionEnabled:YES,但无论怎么点击这个view都无法响应到Category中的点击事件。在这个UIView上加了一个button,点击也是无效的,这是为什么呢?

贴一下关键代码:

    UIView* notificationView = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 44)];

    UIButton* redirectButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [redirectButton addTarget:self action:@selector(**showMessageView**) forControlEvents:UIControlEventTouchUpInside];
    redirectButton.backgroundColor = [UIColor clearColor];
    [redirectButton setTitle:@"跳转!" forState:UIControlStateNormal];
    [redirectButton setUserInteractionEnabled:YES];
    [notificationView addSubview:redirectButton];

    [self.view.window addSubview:notificationView];

无论怎么点击,都无法进入这个UIViewController+NotificationView的showMessageView方法。请大家帮忙捉下虫,谢谢!

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

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

发布评论

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

评论(1

瑶笙 2022-09-06 00:50:16

如果设置都没有问题。
通常会不会是因为View的覆盖所导致的?
或者View被不小心offset了?
通常是小错误。
先检查代码。
XCode6出了新的debug或者能够帮到你。

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