导航栏左侧的按钮问题

2023-07-07移动开发问题
6

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

问题描述

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

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7