UIButton UIControlEventTouchUpInside不会触发,但是UIControlEventTouchDown会触发 [英] UIButton UIControlEventTouchUpInside does not fire, but UIControlEventTouchDown does fire

查看:1173
本文介绍了UIButton UIControlEventTouchUpInside不会触发,但是UIControlEventTouchDown会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现 UIButton 并且我的 UIControlEventTouchUpInside 事件不会触发,即使 UIControlEventTouchDown 会触发。

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];


推荐答案

我假设为什么不采取 UIControlEventTouchUpInside

我在两个不同的ViewControllers中有两个BannerView(广告)。在其中一个它只是在另一个工作正常,我看到如何触摸 UIButton ,并出现第二个图像(较暗)。但选择器没有被击中。然后我意识到, Up -Event是从 UIImageView <的 UISwipeGestureRecognizer 吸收的/ code>下面。一些识别器互相竞争。我搜索了一个概述,看看这些是什么,但一无所获。

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.

另一个解决方案:
如果你看到ButtonState没有改变你有查看你的按钮是否有查看。

Another solution: If you see that the ButtonState doesn't change u have to look if you have a View over your Button.

这篇关于UIButton UIControlEventTouchUpInside不会触发,但是UIControlEventTouchDown会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆