UIButton UIControlEventTouchUpInside 不会触发,但 UIControlEventTouchDown 会触发
我正在实现 UIButton
,并且我的 UIControlEventTouchUpInside
事件没有触发,即使 UIControlEventTouchDown
确实触发了。
UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePathImage = @"img.png";
NSString *filePathImageTap = @"img-tap.png";
UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePathImage];
UIImage *buttonImageTap = [UIImage imageWithContentsOfFile:filePathImageTap];
[btnClose setImage:buttonImage forState:UIControlStateNormal];
[btnClose setImage:buttonImageTap forState:UIControlStateSelected];
[btnClose setImage:buttonImageTap forState:UIControlStateHighlighted];
[btnClose addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnClose];
I am implementing UIButton
and my UIControlEventTouchUpInside
event does not fire, even though UIControlEventTouchDown
does fire.
UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePathImage = @"img.png";
NSString *filePathImageTap = @"img-tap.png";
UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePathImage];
UIImage *buttonImageTap = [UIImage imageWithContentsOfFile:filePathImageTap];
[btnClose setImage:buttonImage forState:UIControlStateNormal];
[btnClose setImage:buttonImageTap forState:UIControlStateSelected];
[btnClose setImage:buttonImageTap forState:UIControlStateHighlighted];
[btnClose addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnClose];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个假设,为什么它不采用
UIControlEventTouchUpInside
:我在两个不同的 ViewController 中有两个“BannerView”(广告)。在一个中它工作得很好,在另一个中我看到了如何触摸
UIButton
并出现第二个图像(较暗)。但选择器没有被击中。然后我意识到,Up
事件被下面的UIImageView
中的UISwipeGestureRecognizer
吸收。一些识别器
相互竞争。我搜索了概述以了解这些女巫,但一无所获。另一个解决方案:
如果您发现 ButtonState 没有改变,您必须查看 Button 上是否有视图。
I have an assumption why it doesn't take the
UIControlEventTouchUpInside
:I had two "BannerView" (Advertisement) in two different ViewControllers. In one it just worked fine in the other I saw how the
UIButton
was touched and the second image (darker) appeared. But the selector was not hit. Then I realized, that theUp
-Event was absorbt by aUISwipeGestureRecognizer
from aUIImageView
below. SomeRecognizer
compete against each other. I searched for an overview to see witch ones these are, but found nothing.Another solution:
If you see that the ButtonState doesn't change u have to look if you have a View over your Button.