UIButton UIControlEventTouchUpInside does not start, but UIControlEventTouchDown fires

I implement UIButton , and the UIControlEventTouchUpInside event UIControlEventTouchUpInside not fire, even if the UIControlEventTouchDown fires.

 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]; 
+6
source share
1 answer

I have an assumption why it is not accepting UIControlEventTouchUpInside :

I had two "BannerView" (Advertising) in two different ViewControllers. In one, it just worked perfectly in the other, I saw how it touched UIButton , and the second image appeared (darker). But the selector did not hit. Then I realized that Up Event is absorbed by a UISwipeGestureRecognizer from a UIImageView below. Some Recognizer compete with each other. I was looking for a review to see the witches, but found nothing.

Another solution: If you see that ButtonState is not changing, you need to see if you have a view above your button.

+3
source

Source: https://habr.com/ru/post/903218/


All Articles