iphone - 自定义 UIBarButtonItem 的事件区域更小

标签 iphone uinavigationcontroller uibutton uibarbuttonitem custom-view

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

最佳答案

我也注意到了这个奇怪的现象。我发现使用容器 UIView 可以解决这个问题。例如:

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];

关于iphone - 自定义 UIBarButtonItem 的事件区域更小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2368120/

相关文章:

iphone - 如何获取 UINavigationController 中使用的 UIView 原点的 x/y 坐标?

ios - 导航项不更改标题

iphone - UINavigationBar 使用动画更改色调颜色

ios - 在填充的白色圆圈 (UIButton) 内创建一个黑色细圆圈(未填充)

ios - 为 UIButton 设置标题时出错

iphone - UIPageViewController 代码中的部分 curl

ios - 如何在 Apple Pay PKPayment 对象数据中获取 ephemeralPublicKey 而不是 wrappedKey 和 EC_v1 而不是 RSA_v1

iphone - 如何在ios中集成谷歌地图?

objective-c - 用于更改 View 的按钮的代码(使用 TabBarController)

ios - 单击按钮时更改图像颜色