UIButton UIControlEventTouchUpInside does not fire, but UIControlEventTouchDown does fire

房东的猫 提交于 2019-12-06 00:34:27

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/8404825/uibutton-uicontroleventtouchupinside-does-not-fire-but-uicontroleventtouchdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!