现成的 Cocoa Spotlight UI 组件

发布于 2024-10-12 21:36:38 字数 239 浏览 6 评论 0原文

我是 Mac 上的开发新手,希望实现一个类似于 Spotlight 的界面 - 主要部分似乎是一个扩展的表格/网格视图。

alt text

我想知道苹果是否提供了一个组件来创建类似的东西,或者在其他地方可用开源组件。

当然,如果没有,我会尝试自己解决一些问题,但它总是值得检查!

提前感谢您的帮助。

I'm new to developing on the Mac and am looking to implement an interface similar to Spotlight's - the main part which seems to be an expanding table/grid view.

alt text

I was wondering if there is a component Apple provides for creating something like this or is available open source else where.

Of course if not I'll just try and work something out myself but it's always worth checking!

Thanks for your help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨凡馨 2024-10-19 21:36:38

新答案(2015 年 12 月)

这些天我会使用垂直堆栈视图 ( NSStackView )。

您可以使用它的隐藏优先级来保证您显示的结果数量适合(它会隐藏那些它不能容纳的结果)。请注意,它不会像表视图重用单元格视图那样重用视图,因此它仅适用于您的情况下有限数量的“结果”,特别是因为添加一堆永远不会的子视图是没有意义的出现。我什至直接说你不应该将它用于你想要滚动的内容列表(在这种情况下,使用表视图)。

优先级设置可用于确保您对“足够”结果的假设不会通过让堆栈视图“牺牲”最后几个结果而导致丑陋的布局问题。

您甚至可以通过最后添加它并将其优先级设置为必需(1000)来模拟 Spotlight 的“Spotlight 首选项”条目(或“显示全部”选项),这样即使其上方的结果条目由于空间不足而被隐藏,它也始终保持不变。

最近,我为 10.11(及更高版本)进行的所有 UI 设计都大量使用了它们。我不断寻找新的方法来简化我的布局。鉴于它们的轻量级,它们应该是您的首选解决方案,除非您需要更复杂的东西(Apple 工程师在 WWDC 视频中表示,它们打算以这种方式使用)。

2011 年旧答案

这是私有 Apple API。我不知道有任何开源项目可以立即模仿它。

如果我尝试这样做,我可能会使用 NSTableView,没有封闭的滚动视图,没有标题,两列,左列中右对齐的浅色文本,右列中易于搜索的图像/文本单元格,以及垂直网格线打开。容器视图将观察表视图的框架更改并相应地调整大小/重新定位。

添加:最好看看右/左对齐文本(甚至列的位置)在具有不同扫描路径的语言中是否不同。示例:阿拉伯语和希伯来语是从右到左阅读的。更好的是适应而不是说“谁在乎”(他轻率地说,同时充分了解他自己的应用程序在这类事情上存在问题:-))。您可以通过确保您的计算机上安装了此类语言,然后在它们之间切换并测试 Spotlight 来对此进行测试。更改语言不应该造成问题,因为语言切换 UI 不依赖于阅读外语。 :-)

New Answer (December, 2015)

These days I'd go with a vertical stack view ( NSStackView ).

You can use its hiding priorities to guarantee the number of results you show will fit (it'll hide those it can't). Note, it doesn't reuse views like a table view reuses cell views, so it's only appropriate for a limited number of "results" in your case, especially since it doesn't make sense to add a bunch of subviews that'll never appear. I'd go so far as to say outright you shouldn't use it for lists of things you intend to scroll (in this case, go with a table view).

The priority setting can be used to make sure your assumption of what should be "enough" results doesn't cause ugly layout issues by letting the stack view "sacrifice" the last few.

You can even emulate Spotlight's "Spotlight Preferences" entry (or a "show all" option) by adding it last and setting its priority to required (1000) so it always stays put even if result entries above it are hidden due to lack of space.

Lately all my UI designs for 10.11 (and beyond) have been making heavy use of them. I keep finding new ways to simplify my layouts with them. Given how lightweight they are, they should be your go-to solution first unless you need something more complex (Apple engineers stated in WWDC videos they're intended to be used in this way).

Old 2011 Answer

This is private Apple API. I don't know of any open-source initiatives that mimic it off-hand.

Were I trying to do it, I might use an NSTableView with no enclosing scroll view, no headers, two columns, right-justified lighter-colored text in the left column, the easily-googled image/text cell in the right column, with vertical grid lines turned on. The container view would observe the table view for frame changes and resize/reposition accordingly.

Adding: It might be a good idea also to see if the right/left justified text (or even the position of the columns) is different in languages with different sweep paths. Example: Arabic and Hebrew are read right-to-left. Better to adapt than to say "who cares" (he says flippantly while knowing full well his own apps have problems with this sort of thing :-)). You can test this by making sure such languages are installed on your computer, then switching between them and testing out Spotlight. Changing languages shouldn't pose an issue since the language switching UI doesn't rely on reading a foreign language. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文