Snow Leopard 与 Lion 中的 NSScrollView 行为(NSScroller 透明度)

发布于 2024-11-27 14:13:25 字数 768 浏览 6 评论 0原文

我在 InterfaceBuilder (XCode 4) 中设置 NSScrollView 时遇到问题,以便它在 Snow Leopard 和 Lion 下看起来都很好。

我有四个 NSView,其中包含使用程序时需要访问的控件。我将这些视图放在一个 NSScrollView 的视图中,当窗口变小以显示所有内容时,它应该显示一个垂直滚动条。 (该视图是一个自定义视图,它返回 [customView isFlipped] == YES 作为唯一的自定义。)

NSScrollView 设置为随着程序窗口的高度垂直自动调整大小。滚动视图内的自定义视图设置为随着 NSScrollView 的宽度水平自动调整大小。 NSScrollView 显示垂直滚动条,并在显示完整内容时自动隐藏它。

通过此配置,一切都可以在 Snow Leopard 下正常运行。但是当我使用 Lion 时,垂直滚动条不会显示在自定义视图的顶部,而是显示在右侧的不透明灰色条内。当滚动条隐藏时,它不会消失,要么是因为窗口足够大,要么是因为 Lion 在不使用时隐藏了滚动条。这看起来真的很不专业,因为我有一些元素跨越了自定义视图的整个宽度,现在距离窗口边框 15 点。 当我将自定义视图的宽度设置为 NSScrollView 的宽度(一个 NSScroller 的宽度+15pt)时,我可以使该行为在 Lion 下正确运行,但如果垂直滚动条是,则视图在 Snow Leopard 中水平滚动显示。 有什么方法可以让它在两个系统上看起来都正确吗?

我使用 Snow Leopard 10.6 SDK 和 Leopard 10.5 作为最低操作系统进行编译。

I have got a problem setting up an NSScrollView in InterfaceBuilder (XCode 4) so that it looks good under both Snow Leopard and Lion.

I've got four NSViews that contain controls that need to be accessed when using the program. I have placed the views below one another inside the View of an NSScrollView, which should display a vertical scroll bar when the window becomes to small to display everything. (The view is a custom view which returns [customView isFlipped] == YES as the only customization.)

The NSScrollView is set to autosize vertically with the height of the program window. The custom view inside the scroll view is set to autosize horizontally with the width of the NSScrollView. The NSScrollView shows the vertical scroll bar and automatically hides it when the full content is shown.

With this configuration all works well under Snow Leopard. But when I use Lion the vertical scroll bar is not displayed on top of the custom view, but inside an opaque, grey bar on the right hand side. This does not disappear when the scroll bar is hidden, either because the window is big enough or because Lion hides the scroll bar when not being used. This looks really unprofessional, because I have got some elements which span the whole width of the custom view and now stop 15 pts from the window border.
I can make this behave correctly under Lion when I set the width of the custom view to the width of the NSScrollView (+15pt for the width of one NSScroller), but then the view scrolls horizontally in Snow Leopard, if the vertical scroll bar is displayed.
Is there any way to get it to look right with both systems?

I am compiling with the Snow Leopard 10.6 SDK and Leopard 10.5 as a minimum OS.

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

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

发布评论

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

评论(1

世界等同你 2024-12-04 14:13:25

您可以检查您的 [NSScroller 类] 的 preferredScrollerStyle 如果它不为零(实际上是 NSScrollerStyleLegacy 但 SDK 10.6 中没有它)然后按照上面提到的那样增加您的视图。另外,不要忘记检查您的滚动器类是否响应该选择器(并使用 PerformSelector: 调用它),因为它仅在 SDK 10.7 中添加。
或者您可以使用 NSScroller 的自定义后代来重载 isCompatibleWithOverlayScrollers 返回 false。即使在 Lion 上,您也将拥有 15pt 宽度的传统滚动条。

You can check your [NSScroller class]'s preferredScrollerStyle and if it's not zero (actually NSScrollerStyleLegacy but you don't have it in SDK 10.6) then increase your view as you mentioned above. Also don't forget to check if your scroller class responds to that selector (and call it with performSelector:) since it was added only in SDK 10.7.
Or you can use your custom descendant of NSScroller that overloads isCompatibleWithOverlayScrollers to return false. Than you'll have legacy scrollers with 15pt width even on Lion.

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