导航栏左侧的按钮问题

Issue with button on the left side of the uinavigation bar(导航栏左侧的按钮问题)
本文介绍了导航栏左侧的按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航栏的左侧有一个按钮.我在那个按钮附近还有一个 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)