Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar button click event firing when clicked on area below it.

enter image description here

I am having navigation bar with custom view as right bar button item. Custom view has two buttons in it. But when i touch area below navigation bar on right side it fires button touch event. I have checked frames of buttons and view by changing background color all are set perfectly. I checked for default iOS apps like clock, calendar, setting, notes etc they all have same behaviour. Touching in red rectangle in screenshots(of default iOS calendar app.) fires touch event of button same is happening with my app too..

Here is 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 behaviour for navigation bar buttons ? Because m having some UI right below these buttons and its top area not responding because of this. Thanks in advance..

like image 388
Aditya Deshmane Avatar asked Mar 11 '13 14:03

Aditya Deshmane


1 Answers

This is normal behavior - two reasons:

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

  2. This may have something to do with the Human Interface Guidelines (sorry, no link. Google it) that say that the minimum touchable area must be 44px. This behavior may be the 'UIBarButtonItem' trying to conform with these requirements.

like image 73
Undo Avatar answered Sep 27 '22 19:09

Undo