我正在开发一个 macOS 应用程序,我以编程方式在 Apple 的 documentation 之后添加 NSToolbarItems我正在添加新的 NSTrackingSeparatorToolbarItem 以支持新的 macOS 11 工具栏外观。
只要我不将 Split View的大小调整到特定宽度以下,跟踪分隔符似乎就可以正常工作,然后分隔符会断开并且看起来不合适。
有没有办法避免这种情况?我知道我可以为 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/