如何在滚动时在 NSTableview 中显示滚动指示器,不滚动时隐藏

How to show scroller indicator in NSTableview when scrolling , hide when not scrolling

我是 MacOS 的新手,我想在滚动时在 NSTableview 中显示滚动条指示器,在不滚动时隐藏。 我正在考虑获得 NSScroller 的委托,这样我就可以检测到它何时滚动,然后 hide/show 它。请帮助

根据 NSTableView reference page:

Table views are displayed in scroll views.

table 视图本身不知道如何滚动。您必须将它放在滚动视图中才能滚动 table。如果您习惯了 iOS 和 UIKit,那就不同了; UITableView 继承自 UIScrollView,因此在该平台上 table 视图 滚动视图。在 MacOS 项目中,如果您将 table 插入到 Xcode 的笔尖或情节提要编辑器中的视图中,Xcode 实际上会插入一个包含 table 视图的滚动视图所以你已经有了你需要的东西。如果您在代码中创建 table,您还需要自己创建滚动视图。

查看 NSScrollView,有一个名为 autohidesScrollers 的 属性,它是...

A Boolean that indicates whether the scroll view automatically hides its scroll bars when they are not needed.

因此,要获得您要求的行为,您需要将滚动视图的 autohidesScrollers 属性 设置为 YES

当然,您也可以在故事板编辑器中进行设置,但是您需要再次查看滚动视图的选项,而不是 table 视图: