Half UIButton does not respond to touch events

I have UIView- which I use as a temporary toolbar. It contains several UIButtons. (Six, I think) in a horizontal line.

The fifth button will only respond to events [ TouchUpInside] when I press the left half, while all other buttons work correctly.

I went crazy, making sure that there were no other species overlapping it, etc. - and everything looks fine.

Any idea on how to explore further? Is there a way to see the "event inspector" to see where touch messages can go?

+3
source share
6 answers

The problem was this:

"" "-" . - - "" - "info light", , .

:

  • "-" ""

- -

  1. "-" " "

... !

. :

alt text

+6

, , . :

for (UIView *v in myButton.superview.subviews){
    NSLog(NSStringFromCGRect(v.frame);
}

, - ( ).

, , - , .

+8

, ? - .

+6

, NSLog() , . , :

UITableView

0

, , , . ! , , . , . , . , - , .

UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIImage *img = [button imageForState:UIControlStateNormal];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:img forState:UIControlStateNormal];
button.showsTouchWhenHighlighted = YES;
[button addTarget:self action:@selector(infoSelected:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
[barItems addObject:barButton];   // NSMutableArray of tab bar items

The second approach, which I decided to use, so that I knew that it would be available, and also to match my splash screen art, should the OS schedule change, I had to follow the same methodology and just save the original PNG to disk and add it to the project as custom image for the button.

// Run these four lines just once in the simulator to save the original info 
// light button image to disk and then eliminate these four lines and create the
// custom button with the image added to the project. Note that it may be a 1x or
// 2x image depending on the simulator device. So run it on both to get two
// versions (changing the name of course).
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIImage *img = [button imageForState:UIControlStateNormal];
NSData *imgData = UIImagePNGRepresentation(img);
BOOL saved = [imgData writeToFile:@"/Users/Shared/InfoLight.png" atomically:NO];
0
source

I noticed that when choosing infoLight, the button can no longer interact. By checking the box "User interaction", I solved the problem.

0
source

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


All Articles