【iOS】为什么在Category中创建的UIView的点击事件无效
PHPz
PHPz 2017-04-17 13:20:02
[iOS讨论组]

我们工程中为了实现应用内的消息通知,所以新建了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方法。请大家帮忙捉下虫,谢谢!

PHPz
PHPz

学习是最好的投资!

全部回复(1)
伊谢尔伦

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号