UIButton UIControlEventTouchUpInside 不会触发,但 UIControlEventTouchDown 会触发

发布于 2024-12-19 23:40:12 字数 803 浏览 3 评论 0原文

我正在实现 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 技术交流群。

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

发布评论

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

评论(1

被翻牌 2024-12-26 23:40:12

我有一个假设,为什么它不采用 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 the Up-Event was absorbt by a UISwipeGestureRecognizer from a UIImageView below. Some Recognizer 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.

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