自定义UIBarButtonItem的较小活动区域 [英] Smaller active area for custom UIBarButtonItem

查看:191
本文介绍了自定义UIBarButtonItem的较小活动区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义UIBarButtonItem的UINavigationBar(它使用UIButton作为其自定义视图)。问题是:自定义按钮的活动区域太大,如果我点击按钮外至少40个像素,它仍然会被注册为按下按钮。这导致意外敲击。如何减少这些按钮上的活动区域?

I have a UINavigationBar with a custom UIBarButtonItem (which uses a UIButton as its custom view). The problem is: the active area of the custom button is much too large, if I tap at least 40 pixels outside the button, it still gets registered as a tap on the button. This results in accidental taps. How can I reduce the active area on these buttons?

推荐答案

我也注意到了这种奇怪现象。我发现使用容器UIView修复了这个问题。例如:

I noticed this weirdness too. I found that using a container UIView fixes this. For example:

UIButton *menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButton addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];
[menuButton setImage:[UIImage imageNamed:@"menuIcon"] forState:UIControlStateNormal];
UIView *menuButtonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButtonContainer addSubview:menuButton];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButtonContainer];

这篇关于自定义UIBarButtonItem的较小活动区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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