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

标签 swift macos appkit macos-big-sur

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

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

跟踪分隔符按预期工作 enter image description here

当 Split View尺寸低于特定宽度时,分隔符会断开。 enter image description here

有没有办法避免这种情况?我知道我可以为 Split View设置最小尺寸,但是有没有办法让它们保持同步(我不想硬编码最小宽度)?尤其是当用户动态添加工具栏项时。

提前致谢。

最佳答案

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

我在玩邮件应用程序时注意到一个有趣的行为,当预览 Pane 显示 NSTrackingSeparatorToolbarItem 时会跟随 Split View的大小调整,但在预览折叠时工具栏会改变外观并变得像静态工具栏。此外,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
}

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

关于swift - 如何在调整 SplitView 大小时避免 NSTrackingSeparatorToolbarItem 溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64837040/

相关文章:

cocoa - 为什么在 Mac 上, NSReadPixel() 会导致 "_NSReadPixel",从 : _main in cctJJibI. o ld : symbol(s) not found? 引用

objective-c - NSTextView查找栏的下一个关键 View

ios - 如何在 Swift 5.0/Xcode 中使用🧨 强制解包

ios - 删除图表上线上的折线图值

ios - 解析 PFQuery 返回 nil (swift)

c++ - OSX,USB 海量存储发现

ios - 如何使用 Mac Catalyst 将 iPad 应用程序移植到 Mac 上设置 "Help"菜单选项?

ios - Mixpanel 设备 token 消失

macos - mac clang ld 出现错误 : unknown option: --gc-sections

cocoa - 获取钥匙串(keychain)中的证书