UINavigationBar UIBarButtonItems比所需的点击区域大得多

dav*_*ave 35 iphone uinavigationbar uibarbuttonitem

希望有人可以帮助我 - 我在网上搜索答案,但找不到 -

添加到UINavigationBar的UIBarButtonItem具有比所需更大的点击区域 - 例如,打开任何项目,你有一个带按钮的导航栏,点击按钮结尾和导航栏标题之间​​的任意位置 - 按钮点击,当你明显没有点击按钮时 -

也可以尝试这一点 - 点击导航栏下方,按钮下方,按钮点击导航栏下方约5个像素 -

我的问题是这个 -

我已经增加了一个自定义首部和按钮,用于一个tableview-但是当我点击标题中的按钮,所述按钮UINavigationBar的触发对那些5+像素代替按钮在tableview中报头 -

我做了一个测试,并从UINavigationBar中删除了按钮,有趣的是,对于导航栏下方的5个像素,即使导航栏中没有按钮,标题中的按钮也不会触发 -

它几乎像导航栏一样保留了低于其自身的5个像素作为点击空间 -

我的问题是这个 -

有人可以告诉我如何使导航栏没有为其按钮抓取额外的5+像素?

非常感谢 ;)

Dam*_*ito 5

这是我找到的唯一解决方案.创建自定义按钮的容器:

//Create a container for the button
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 44)];

//Create a smaller button
UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 25)];
[closeButton setTitle:@"Cancel" forState:UIControlStateNormal];
//center the title
closeButton.titleEdgeInsets = UIEdgeInsetsMake(23, 0, 0, 0);

[buttonContainer addSubview:closeButton];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonContainer];
Run Code Online (Sandbox Code Playgroud)


rou*_*ter 2

简短的回答是……不应该尝试摆脱它们。这是关于易用性。顶部的导航栏往往意味着人们点击的位置低于您的预期。始终保留该间隙,或者具有足够大的点击区域,以便用户将手指刺向“导航栏下方”项目的中间将避开死区。