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