本文介绍了NSToolbarFlexibleSpaceItem 是 Swift 中 NSSplitViewItem 的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几乎所有的 macOS 官方应用程序都有这个工具栏的功能,其中 NSToolbarItem 灵活空间被限制在 NSSplitViewItem 视图中.我首先想到 NSToolbar 上可能有 3 个不同的部分.但它只是一个工具栏.您可以打开 Notes 应用程序并自定义工具栏.

Almost all macOS official apps have this toolbar's feature which the NSToolbarItem flexible space is constraint to NSSplitViewItem view. I first thought maybe there are 3 different sections on NSToolbar. But it just ONE toolbar. You can open Notes app and customize the toolbar.

  • 检测到第一个灵活空间并与第一个拆分视图项一起移动.
  • 检测到第二个灵活空间并与第二个拆分项目一起移动.
  • 其余的只是普通的灵活空间.
  • 如果只有两个灵活空间,则第二个将充当普通的灵活空间.同样的事情也适用于一个和/或灵活的空间.

我猜这就是 Apple 配置灵活空间项的方式.

I guess this is how Apple configure the flexible space items.

我发现了这个 JWToolbarAdaptiveSpaceItem 但它是可移动的,不能像 Note 应用程序那样用灵活的空间项目替换.

I found this JWToolbarAdaptiveSpaceItem but it's removable and it cannot be replaced with flexible space item like Note apps does.

还有另一个 stackoverflow 的问题(我现在找不到)问到这个问题,但答案是添加不是 NSToolbar 的假视图和按钮.

There is another stackoverflow's question (I couldn't find it now) asked about this but the answer is adding fake views and buttons which is not NSToolbar.

因此,有人知道如何实现这一目标吗?

Thus, does anyone know how to achieve this?

(对不起我的英语)

推荐答案

从 macOS 11 Big Sur 开始,这是由 NSTrackingSeparatorToolbarItem 处理的,它与 NSSplitView 的分隔符进行交互代码>.NSToolbarItem 上还有一个新的 navigational 属性,可以影响项目位置.

As of macOS 11 Big Sur, this is handled by NSTrackingSeparatorToolbarItem, which interacts with the dividers of an NSSplitView. There is also a new navigational property on NSToolbarItem that can influence item locations.

我认为以前的 macOS 版本没有内置的方法来做到这一点.

I do not think there is a built-in way to do this on previous macOS versions.

这篇关于NSToolbarFlexibleSpaceItem 是 Swift 中 NSSplitViewItem 的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 18:30