如何在调整 SplitView 大小时避免 NSTrackingSeparatorToolbarItem 溢出?

How to avoid NSTrackingSeparatorToolbarItem from overflowing when resizing a SplitView?

我正在开发一个 macOS 应用程序,我在 Apple documentation 之后以编程方式添加 NSToolbarItems,我正在添加新的 NSTrackingSeparatorToolbarItem 以支持新的 macOS 11 工具栏外观。

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

跟踪分隔符按预期工作

当拆分视图尺寸低于一定宽度时,分隔符会破裂。

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

提前致谢。

好的,我想我明白了...

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

所以我在 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
}

请注意,拆分行为仍然会发生,但是当发生这种情况时,工具栏的外观和感觉会发生变化,并且您不会像我所经历的那样看到任何难看的拆分视图分隔线。希望这对可能 运行 解决此问题的其他人有所帮助。