导航栏左侧的按钮问题 [英] Issue with button on the left side of the uinavigation bar

查看:33
本文介绍了导航栏左侧的按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航栏的左侧有一个按钮.我在那个按钮附近还有一个 UIButton.

I have a button on the left side of the navigation bar. I also have a UIButton near that button.

现在,当我单击导航栏下方的按钮时,在许多情况下,导航栏上的按钮会被单击.

Now when I click the button thats below the navigation bar, in many cases, the button on the nab bar gets clicked.

知道为什么会这样吗?有什么建议吗?

Any idea why this is happening? Any suggestions ?

谢谢.

图片:如果您单击红色按钮内的任意位置,导航栏左上角的按钮仍会被按下.

image: if you click anywhere inside the red button, the top left button of the nav bar still gets pressed.

导航栏按钮代码:

UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
[leftButton setShowsTouchWhenHighlighted:NO];
[leftButton setImage:[UIImage imageNamed:@"deals.png"] forState:UIControlStateNormal];
[leftButton setImage:[UIImage imageNamed:@"deals_down.png"] forState:UIControlStateSelected];
[leftButton setImage:[UIImage imageNamed:@"deals_down.png"] forState:UIControlStateHighlighted];
[leftButton addTarget:self action:@selector(dealsButtonPressed:) forControlEvents:UIControlEventTouchDown || UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem =  [[[UIBarButtonItem alloc] initWithCustomView:leftButton] autorelease];
[leftButton release];

推荐答案

UINavigationButtons 的可点击区域比它的视图要大得多,Apple 这样做是为了便于使用.如果你真的想要两个彼此靠近的按钮,你必须继承 UINavigationBar,更具体地说,覆盖触摸事件,获取触摸坐标并按照你认为合适的方式行事.更多信息这里.

UINavigationButtons have a much larger tappable area than it's view, Apple made it this way for ease of use. If you really want to have two buttons that close to each other you have to subclass UINavigationBar, more specifically, override the touch events, get the touch coordinates and act as you see fit. More info here.

这篇关于导航栏左侧的按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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