Pressing a button on the navigation bar causes a click on clicking on the area below it.

enter image description here

I have a navigation bar with a custom view as an element of the right button. User view has two buttons. But when I touch the area below the navigation bar on the right side, it triggers a button click event. I checked the button frames and view, changing the background color, they are all set perfectly. I checked the default iOS apps like clock, calendar, settings, notes, etc., They all have the same behavior. Touching the red rectangle in the screenshots (the default iOS calendar application) triggers a button touch event, it also happens with my application.

Here is the code ..

UIView* navigationButtonsView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 44.0f)]; UIButton *p = [UIButton buttonWithType:UIButtonTypeCustom]; [p setImage:[UIImage imageNamed:@"PBtn.png"] forState:UIControlStateNormal]; [p addTarget:self action:@selector(PButtonPushed:) forControlEvents:UIControlEventTouchUpInside]; [p setFrame:CGRectMake(43, 0, 57, 44)]; [navigationButtonsView addSubview:p]; UIButton *o = [UIButton buttonWithType:UIButtonTypeCustom]; [o addTarget:self action:@selector(oButtonPushed:) forControlEvents:UIControlEventTouchUpInside]; [o setFrame:CGRectMake(0, 0, 38, 44)]; [o setImage:[UIImage imageNamed:@"O.png"] forState:UIControlStateNormal]; [navigationButtonsView addSubview:o]; UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:navigationButtonsView]; [musicVC.navigationItem setRightBarButtonItem: barItem animated:NO]; 

How to change this default iOS behavior for navigation bar buttons? Because m has some user interface right below these buttons, and its upper area is not responding because of this. Thanks in advance.

+6
source share
1 answer

This is normal behavior - two reasons:

  • iOS doesn't know how big your finger is, so it has to decide where to put the touch. In this case, the navigation bar overrides the table view.

  • This may have something to do with the User Interface Guides (sorry, no link provided), which say that the minimum tangible area should be 44 pixels. This behavior may be "UIBarButtonItem" trying to meet these requirements.

+1
source

All Articles