gpt4 book ai didi

macos - 侧栏中的 Big Sur 工具栏项目

转载 作者:行者123 更新时间:2023-12-03 14:13:55 24 4
gpt4 key购买 nike

在 Big Sur 中,Xcode 和 Calendar 的工具栏项目在打开时保留在侧边栏上,但在侧边栏折叠时在左侧仍然可见。
侧边栏打开:
enter image description here
侧边栏折叠:
enter image description here
"Adopt the New Look of macOS"在 13:55,John 说“放置在分隔符 [sidebarTrackingSeparator] 之前的项目将出现在全高侧边栏上”,就像它们在 Xcode 和日历中一样。我一直无法完成这项工作。
Here's a sample project这说明了这个问题。我使用了 IB 定义的“带有侧边栏的窗口 Controller ”,并添加了一个用于切换侧边栏的工具栏项。在 NSWindowController 的子类中,我插入 .sidebarTrackingSeparator.toggleSidebar元素:

override func windowDidLoad() {
// Sometimes the toolbar items aren't loaded yet--async is a quick and dirty way to prevent a crash
DispatchQueue.main.async {
self.window?.toolbar?.insertItem(withItemIdentifier: .sidebarTrackingSeparator, at: 1)
}
}

有时这不起作用(切换按钮保留在侧边栏的右侧)。有时侧边栏切换会放在溢出菜单中:
enter image description here
在 WWDC session 之外,我还没有看到任何关于实现此工具栏设计的讨论。有没有人能够让这个工作?

最佳答案

这是 IB/Code 时间不一致。在您添加 .sidebarTrackingSeparator 之前,Interface Builder 会配置并安装工具栏。工具栏项。
所以你在做正确的事情,只是太晚了。太晚了。我认为重要的是在窗口上设置工具栏之前将项目放在那里。
不幸的是,这在 IB 中是不可能的,除非我相信您创建了一个全新的工具栏并重新分配它。但这是一个坏主意,因为那样您可能会在自动保存工具栏状态时遇到麻烦。
诀窍是在 Interface Builder 中配置分隔符。如果你看 ObjC documentation for this constant ,你会看到一个更长的名字:NSToolbarSidebarTrackingSeparatorItemIdentifier .
我们在这里能做的最好的事情就是希望符号的名称与标识符的值相同。如果你真的想验证这一点,你可以在调试器中打印符号的值:

(lldb) po NSToolbarSidebarTrackingSeparatorItemIdentifier
NSToolbarSidebarTrackingSeparatorItemIdentifier
如果我们在 IB 中创建一个自定义工具栏项,并根据 John 的视频添加它...
Interface Builder with a custom toolbar item positioned in the toolbar. The item has the identifier NSToolbarSidebarTrackingSeparatorItemIdentifier set in the attributes inspector
低下看:
enter image description here

关于macos - 侧栏中的 Big Sur 工具栏项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63512030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com