UINavigationBar UIBarButtonItems比所需的点击区域大得多 [英] UINavigationBar UIBarButtonItems much larger click area than required

查看:110
本文介绍了UINavigationBar UIBarButtonItems比所需的点击区域大得多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

hopefully someone can help me out- iv'e scoured the net for the answer and cannot find one-

添加到UINavigationBar的UIBarButtonItems有一个更大的点击区域比例要求 -
例如,打开任何项目,你有一个导航栏,按钮点击按钮结束和导航栏标题之间​​的任何地方 - 按钮点击,当你明显没有点击按钮 -

the UIBarButtonItems added to UINavigationBar have a much larger click area than required- for example, open up any project you have a nav bar with buttons on- click anywhere between the end of the button and the title of the nav bar- the button clicks, when you clearly did not click on the button-

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

also try this- click underneath the nav bar, below the button, the button clicks for about 5+ pixels below the nav bar-

我的问题是这个 -

my problem is this-

我已经添加了一个带有按钮的自定义标题到tableview-但是当我点击按钮时标题,UINavigationBar按钮触发那些5+像素而不是tableview标题中的按钮 -

i have added a custom header with buttons to a tableview- but when i click the buttons in the header, the UINavigationBar buttons trigger for those 5+ pixels instead of the buttons in the tableview header-

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

i did a test, and removed the buttons from UINavigationBar and what is interesting is that for the 5 pixels below the nav bar, the buttons in the header will not trigger even though there are no buttons in the nav bar-

它几乎就像导航栏在自身下方保留了大约5个像素作为点击空间 -

its almost like the nav bar has reserved some 5+ pixels below itself as click space-

我的问题是这个 -

my question is this-

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

can someone tell me how to make the nav bar not grab those extra 5+ pixels for its buttons?

非常感谢;)

推荐答案

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

This is the only solution I found. Create a container of the custom button:

//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];

这篇关于UINavigationBar UIBarButtonItems比所需的点击区域大得多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆