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

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

问题描述

我在导航栏的左侧有一个按钮。我在该按钮附近也有一个UIButton。

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

现在,当我点击导航栏下方的按钮时,在很多情况下,点击了nab栏上的按钮。

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.

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

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