1

我正在开发一个 macOS 应用程序,并按照 Apple 的文档以编程方式添加 NSToolbarItems ,并且我正在添加新的 NSTrackingSeparatorToolbarItem 以支持新的 macOS 11 工具栏外观。

只要我不将拆分视图的大小调整到一定宽度以下,跟踪分隔符似乎就可以正常工作,然后分隔符就会出现并且看起来不合适。

跟踪分离器按预期工作 在此处输入图像描述

当拆分视图大小低于某个宽度时,分隔符会中断。 在此处输入图像描述

有没有办法避免这种情况??我知道我可以为拆分视图设置最小尺寸,但是有没有办法让它们保持同步(我不想硬编码最小宽度)?特别是如果用户动态添加工具栏项。

提前致谢。

4

1 回答 1

1

好吧,我想我明白了……

在使用 Mail 应用程序时,我注意到一个有趣的行为,当预览窗格显示 NSTrackingSeparatorToolbarItem 时,会跟随拆分视图的大小调整,但是当预览折叠时,工具栏会改变外观并变成静态工具栏。此外, NSTrackingSeparatorToolbarItem 保持原位,看起来就像一个普通的工具栏分隔符(就像你可能在其他操作系统上找到的那样)。

所以我用我的工具栏在 IB 中玩耍并发现了我的错误,我的 NSWindow 将标题栏设置为透明!

我取消选中该选项,瞧,我可以自动复制邮件应用程序的外观和感觉。

此属性必须在 NSWindow 中设置为 false

@available(macOS 10.10, *)
open var titlebarAppearsTransparent: Bool

当然工具栏样式应该设置为统一

@available(macOS 11.0, *)
    public enum ToolbarStyle : Int {
    // The default value. The style will be determined by the window's given configuration
    case automatic = 0
    // The toolbar will appear below the window title
    case expanded = 1
    // The toolbar will appear below the window title and the items in the toolbar will attempt to have equal widths when possible
    case preference = 2
    // The window title will appear inline with the toolbar when visible
    case unified = 3
    // Same as NSWindowToolbarStyleUnified, but with reduced margins in the toolbar allowing more focus to be on the contents of the window
    case unifiedCompact = 4
}

请注意,突破行为仍然会发生,但是当这种情况发生时,工具栏会改变外观,并且您不会看到任何像我经历过的丑陋的拆分视图分隔线。希望这对可能遇到此问题的其他人有所帮助。

于 2020-11-16T10:55:23.790 回答