通过 UIToolBar 的 UIBarButtonItem 在 iOS13 上不显示

2023-12-31

我通过UIToolBar将UIBarButtonItem设置为iOS13上navigationItem的titleView。

构建并运行后,UIBarButtonItem 未按预期显示。

// note
UIBarButtonItem *noteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCompose target:self action:@selector(noteViewAction)];

// camera
UIBarButtonItem *cameraButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCamera target:self action:@selector(cameraViewAction)];

// spacer
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
space.width = 50.0;


// Toolbar
UIToolbar *toolbar;
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 44.0f)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight;
toolbar.items = [NSArray arrayWithObjects:space, noteButton, space, cameraButton, nil];
toolbar.backgroundColor = [UIColor clearColor];

[self.navigationItem setTitleView:toolbar];

这段代码中,UIBarButtonItem在iOS12.4.1及更早版本中正确显示。

Xcode 控制台日志中显示以下消息。

2019-08-29 19:22:39.208598+0900 UINavigationItemBugOnIos13[559:49829] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x2839cf980 h=--& v=--& _UIToolbarContentView:0x102c14c20.width == 0   (active)>",
    "<NSLayoutConstraint:0x2839cff20 UIImageView:0x102d2aff0.width <= _UIModernBarButton:0x102d29c40.width   (active)>",
    "<NSLayoutConstraint:0x2839c00f0 UIImageView:0x102d2ca80.width <= _UIModernBarButton:0x102d2b550.width   (active)>",
    "<NSLayoutConstraint:0x2839c9720 H:|-(0)-[_UIButtonBarStackView:0x102c18130]   (active, names: '|':_UIToolbarContentView:0x102c14c20 )>",
    "<NSLayoutConstraint:0x2839c9770 _UIButtonBarStackView:0x102c18130.trailing == _UIToolbarContentView:0x102c14c20.trailing   (active)>",
    "<NSLayoutConstraint:0x2839cd9f0 'IB_Leading_Leading' H:|-(16)-[_UIModernBarButton:0x102d29c40]   (active, names: '|':_UIButtonBarButton:0x102d29a60 )>",
    "<NSLayoutConstraint:0x2839ce490 'IB_Leading_Leading' H:|-(>=10)-[_UIModernBarButton:0x102d2b550]   (active, names: '|':_UIButtonBarButton:0x102d2b370 )>",
    "<NSLayoutConstraint:0x2839cda40 'IB_Trailing_Trailing' H:[_UIModernBarButton:0x102d29c40]-(>=11.5)-|   (active, names: '|':_UIButtonBarButton:0x102d29a60 )>",
    "<NSLayoutConstraint:0x2839ce4e0 'IB_Trailing_Trailing' H:[_UIModernBarButton:0x102d2b550]-(16)-|   (active, names: '|':_UIButtonBarButton:0x102d2b370 )>",
    "<NSLayoutConstraint:0x2839c4140 'UISV-canvas-connection' UILayoutGuide:0x2823ecfc0'UIViewLayoutMarginsGuide'.leading == UIView:0x102c3eb90.leading   (active)>",
    "<NSLayoutConstraint:0x2839c42d0 'UISV-canvas-connection' UILayoutGuide:0x2823ecfc0'UIViewLayoutMarginsGuide'.trailing == UIView:0x102c3ee70.trailing   (active)>",
    "<NSLayoutConstraint:0x2839c4320 'UISV-spacing' H:[UIView:0x102c3eb90]-(0)-[_UIButtonBarButton:0x102d29a60]   (active)>",
    "<NSLayoutConstraint:0x2839c4370 'UISV-spacing' H:[_UIButtonBarButton:0x102d29a60]-(0)-[UIView:0x102c3ed00]   (active)>",
    "<NSLayoutConstraint:0x2839c43c0 'UISV-spacing' H:[UIView:0x102c3ed00]-(0)-[_UIButtonBarButton:0x102d2b370]   (active)>",
    "<NSLayoutConstraint:0x2839cf070 'UISV-spacing' H:[_UIButtonBarButton:0x102d2b370]-(0)-[UIView:0x102c3ee70]   (active)>",
    "<NSLayoutConstraint:0x2839c9590 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2823ecfc0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x102c18130 )>",
    "<NSLayoutConstraint:0x2839c9630 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x2823ecfc0'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x102c18130 )>"
)

Will attempt to recover by breaking constraint 
NSLayoutConstraint:0x2839c00f0 UIImageView:0x102d2ca80.width <= _UIModernBarButton:0x102d2b550.width   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

苹果开发者论坛上有一个问题描述了同样的现象。

https://forums.developer.apple.com/thread/121474 https://forums.developer.apple.com/thread/121474

据此,这是一个限制问题,但它是关于私有API的部分,并且写道不可能进行进一步的调查和解决。

本文指出您使用了 UIStackView 而没有使用 UIToolBar。

我已经就这个问题向苹果报告了一个bug,但目前苹果还没有回应,而且这个问题在iOS13新测试版(iOS13.1 beta)中也没有得到解决。

在iOS13中,通过UIToolBar的UIBarButtonItem变得不可用了吗?

我应该使用 UIStackView 而不是 Apple 开发者论坛文章中描述的 UIToolBar 吗?


从 iOS 13 开始,您需要给工具栏一个框架。知道问题是objective-c,但回复很快。

   doneToolbar.frame = CGRect(x: 0,
                              y: 0,
                              width: view.bounds.width,
                              height: 40)

另一个解决方案是将工具栏放在stackview

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 UIToolBar 的 UIBarButtonItem 在 iOS13 上不显示 的相关文章

随机推荐

  • PHPIniDir 在 Windows 7 下损坏?

    我有一台在 Windows XP 机器上运行的服务器 使用 Apache2 PHP 和 MySQL 我最近升级到 Windows 7 但在运行时遇到了问题 Apache 工作正常 PHP 工作正常 但我似乎无法让它与php ini file
  • 如何在打字时启用历史选择列表

    我正在尝试成为 PowerShell 的一员 并发现了一项我非常喜欢的功能 但不知道如何使其始终如一地工作 PowerShell 可以进入一种模式 在您键入时显示增量更新的历史项目选择列表 然后 您可以通过向上和向下箭头浏览它们来选择要运行
  • Ruby 函数检查一个数字是否能被 5 整除并且是偶数

    def is even n remainder when divided by 2 n 2 if remainder when divided by 2 0 return true else return false end end def
  • 在 Flutter 中使用 iOS 行为时更改 ListView 反弹颜色

    当创建一个ListView 文档中的示例 https flutter io docs cookbook lists basic list 当使用带有 Flutter 的 iOS 模拟器滚动时 我们如何更改出现在列表顶部的反弹颜色 ListV
  • 如何使用 Cython 进行覆盖率分析

    我正在尝试使用一些 Cython 代码运行覆盖率分析pytest cov和工作服 io 我已经构建了启用跟踪的扩展模块 并借助以下链接运行分析 http docs cython org src tutorial profiling tuto
  • 如果远程仓库不可用,如何为 Spring Cloud Config 服务设置本地后备配置?

    我们计划在我们的服务中使用 Spring Cloud Config 我们最担心的是 当容器启动时 它依赖 github 始终可用 以便它可以拉取配置文件 如果 github 宕机 缓解该问题的最佳实践是什么 我正在考虑存储配置的本地文件夹作
  • 在单个 build.gradle 文件中多次调用同一任务

    我有一个自定义 Gradle 插件 它将从模板文件生成 Java 文件 我在不同位置有几个这样的模板文件 我需要 编译 所有这些文件以生成我需要的 Java 文件 获得文件后 我想将它们打包到 jar 中 我认为可以做到这一点的一种方法是从
  • 在 .NET 中打印 - 从毫米到像素的转换

    如何将用户输入从毫米转换为像素 以便将其打印在页面的正确位置 我使用以下代码 private void document PrintPage object sender PrintPageEventArgs e float dpiX e G
  • zip 函数帮助处理元组

    我希望有人能帮助我解决我遇到的问题 我有大量的元组 gt 500 如下所示 2 1 3 6 1 2 5 5 3 0 1 6 10 1 1 4 0 3 3 0 我的代码片段如下 sum1 A B C D creates a tuple of
  • get 返回 hazelcast 3.5 中超类 ArrayList 的值

    我在使用 hazelcast 3 5 时遇到序列化问题 当一个 hazelcast 客户端 Java 输入 class 的值时 public class MyType extends ArrayList
  • 使用 Firestore 和 Typescript 实现动态 Where 条件

    我正在尝试实现存储库模式火库Firebase 和打字稿 Code import firestore from firebase admin import ISearchCriteria from ISearchCriteria export
  • libgcrypt.lib 中未解析的外部符号

    如果我在 lib library 文件中发现未解析的外部符号 我必须做什么 如果我在 c 或 cpp 中发现无法解析的外部符号 我可以修复它 但是当我在 lib library 文件中发现未解析的外部符号时 我该如何解决这个问题 就我而言
  • @Input 是否提供双向绑定?

    我认为 Input的工作方式会直接给出一个大大的 不 对于这个问题 然而 今天我偶然发现了一些奇怪的行为 或者也许我一直对 Input 的想法是错误的 我做了一个堆栈闪电战 https stackblitz com edit angular
  • F# 是一种可用于 .net windows 开发的语言吗

    我一直听说过 F 微软现在有一个人在雷蒙德某处写博客和编码 你真的可以用 F 编写 GUI 代码吗 我很想看到一个例子 例如向表单添加按钮并订阅 onclick 事件 F 是否可以完全访问所有 Net 老实说 我很好奇 我知道我可以用谷歌搜
  • MySQL解释计划中“选择优化掉的表”的含义

    是什么意思Select tables optimized awayMySQL中的解释计划 explain select count comment count from wp posts id select type table type
  • 无法解析构造函数 ArrayAdapter

    无法在自定义对话框中使用 ArrayAdapter 这是我收到的错误 https i stack imgur com 3yGN5 png 您收到该错误是因为ArrayAdapter构造函数要求第一个参数是Context目的 由于您是从内部调
  • 未捕获的类型错误:Object.values 不是 JavaScript 函数

    我有一个简单的对象 如下所示 var countries Argentina 1 Canada 2 Egypt 1 我需要创建两个数组 第一个数组是对象中所有键的数组 我通过以下方式创建了这个数组 var labels Object key
  • matplotlib 中的复杂极坐标图

    我想创建一个类似于以下的极坐标图 我找不到如何在不同角度范围内添加两个不同函数的示例 我不需要中间的径向偏移 但可能会很好 任何指针 已知的例子都是超级的 它看起来就像其他绘图一样matplotlib 即如果你想绘制两条曲线 你可以调用pl
  • 使用 C# 将记录插入 MySQL 数据库

    我目前正在使用 C WPF 开发一个应用程序 我正在尝试将数据存储到 MySQL 数据库中 下面是我的代码 MySqlCommand cmd new MySqlCommand conn cmd CommandText INSERT INTO
  • 通过 UIToolBar 的 UIBarButtonItem 在 iOS13 上不显示

    我通过UIToolBar将UIBarButtonItem设置为iOS13上navigationItem的titleView 构建并运行后 UIBarButtonItem 未按预期显示 note UIBarButtonItem noteBut