iphone - UIToolBar 意外地在 UIBarButtonItem 实例上注册点击,即使在距它们相当远的地方点击也是如此

标签 iphone cocoa-touch ios uibarbuttonitem uitoolbar

我想知道是否有其他人注意到这种行为 - 搜索网络或这些论坛没有为我挖掘任何东西:

[更新:从 iOS 7.0.1 开始,iPhone(但不是 iPad)仍然存在问题]

在 iOS 4.2.1 上的 iPhone 应用程序中,如果您
- 有一个工具栏(UIToolBar - 无论是显式创建还是由UINavigationController 提供)充满UIBarButtonItem 样式实例UIBarButtonItemStyleBordered(圆角矩形按钮)
- 并且您在它们之间有相当大的空白空间(例如,通过在两个按钮之间使用系统类型UIBarButtonSystemItemFlexibleSpaceUIBarButtonItem 实例将一个放在远处左边,另一个在最右边)
我观察到以下意外行为:

如果您在距离最近的按钮相当远的工具栏上的空白处点击,该按钮 - 意外地 - 仍然记录点击强>.

虽然您可以将其视为一项功能,但它也可能会让用户感到不安,尤其是当点击位置没有清楚地表明调用了哪个功能时。 在更有可能发生意外点击的“固定” View 中(例如,其元素与工具栏接壤的游戏),此行为增加了意外调用功能的可能性。

在我的具体情况下,您可以点击按钮右侧的最多 56 像素,并且仍然让它注册一次点击。

此行为在模拟器和实际设备上都会发生。 有没有其他人有这种经验?我是不是忽略了什么?

感谢聆听/帮助。

最佳答案

我还发现这是一个很大的问题(我有一个按钮位于 UIToolBar 的正上方,我发现大多数时候我尝试用拇指点击那个按钮,但我最终点击了 UIToolBar 中的空白区域UIToolbar 并改为激活其中一个工具栏按钮)。

我能找到的避免此问题的唯一方法是在按钮和灵活空间之间放置一个非功能按钮。这样,在灵活空间内的任何触摸都只会激活非功能按钮,而不会发生任何事情。我用 UIBarButtonItem initWithCustomView 实现了这个,并且只使用了带有 1x1 透明图像的 UIImageView(请原谅我!):

[myToolbar setItems:[NSArray arrayWithObjects:
  [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                 target:nil 
                                                 action:nil] autorelease],
  [[[UIBarButtonItem alloc] initWithCustomView:
    [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1x1Transparent.png"]] autorelease]] autorelease],
  [[[UIBarButtonItem alloc] initWithTitle:@"Button 1" 
                                    style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(button1Pressed:)] autorelease],
  [[[UIBarButtonItem alloc] initWithTitle:@"Button 2" 
                                    style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(button2Pressed:)] autorelease],
  [[[UIBarButtonItem alloc] initWithTitle:@"Button 3" 
                                    style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(button3Pressed:)] autorelease],
  [[[UIBarButtonItem alloc] initWithCustomView:
    [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1x1Transparent.png"]] autorelease]] autorelease],
  [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                 target:nil 
                                                 action:nil] autorelease], nil]];   

关于iphone - UIToolBar 意外地在 UIBarButtonItem 实例上注册点击,即使在距它们相当远的地方点击也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5113258/

相关文章:

iphone - Iphone 6.0 模拟器视网膜显示屏 4.0 英寸顶部和底部有空白

iphone - 开发中的 iPhone 应用程序是否比发布后运行速度更慢?

ios - 在 ios safari 上上传文件的替代方法是什么?

iphone - 沙盒游戏中心转事件通知不一致

iphone - RegexKitLite 问题

iphone - iOS:如何在应用程序中进行I18N/本地化?

cocoa - 如何将 NSManagedObject 从一个上下文复制或移动到另一个上下文?

在 iOS 自定义键盘中使用时不支持 iOS CoreBluetooth 状态

ios - 什么是用于播放 Mp3 等音乐的 AVPlayerViewController 的委托(delegate)方法

ios - 填充 UILabel 文本以填充其宽度