【问题标题】:Why UIBarButtonItem's foucs area smaller than prior in iOS11?为什么 iOS11 中 UIBarButtonItem 的焦点区域比以前小?
【发布时间】:2023-03-28 05:31:01
【问题描述】:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];  
[button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];  
[button sizeToFit];  
[button setBackgroundColor:[UIColor greenColor]];  
[button addTarget:self  
           action:@selector(tap)  
 forControlEvents:UIControlEventTouchUpInside];  
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 

当我在 iOS 10 或更早版本中运行时,我可以在此按钮的边界之外触摸超过 5-10 像素并触发此操作(点击)。

但在新发布的iOS11中,我只能在区域内触发动作。

如何才能喜欢 iOS10 或更早版本的性能? new navigationItem 的新布局是否会引出这个问题?

【问题讨论】:

  • 其实我认为之前的行为是bug。
  • @matt 我认为早期的行为对于可能无法准确点击按钮的大屏幕或大手指的用户来说更方便。
  • 问题是栏按钮项目可能会阻止我在主视图中点击按钮!

标签: ios uinavigationbar uibarbuttonitem uinavigationitem


【解决方案1】:

我只将图像设置为条形按钮项目,然后为 iOS 11 调整 barbutton.imageInsets。对于低于 11 的 iOS,我应用与您相同的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    相关资源
    最近更新 更多