将 NSScroller 覆盖在内容上
有没有办法将 NSScroller 覆盖在滚动视图的内容上(就像在 iOS 中一样)?我已经尝试过几种方法:
a) 设置滚动视图内容视图 (NSClipView) 的框架以扩展到滚动条的边界
b) 添加 NSScroller 对象作为滚动视图的子视图(位于我想要的位置)
c) 创建一个完全自定义的滚动视图并将其放置为子视图(这有效,但这意味着我需要重写所有功能NSScroller 的)
Sparrow 似乎成功地做到了这一点,而且它似乎是通过常规的 NSScroller 子类来做到这一点的(因为它响应滚动在系统偏好设置>>外观中设置)。问题并不是真正绘制滚动条,而是让它覆盖了内容。
任何建议表示赞赏:-)
Is there any way to overlay the NSScroller over the content of the scroll view (like in iOS)? I've already tried several approaches:
a) setting the frame of the scroll view content view (NSClipView) to extend into the bounds of the scroller
b) adding an NSScroller object as a subview of the scroll view (positioned where I want)
c) creating an entirely custom scroller view and placing it as a subview (this worked, but that would mean that I need to rewrite all the functionality of NSScroller)
Sparrow seems to successfully do this, and it seems to do it through a regular NSScroller subclass (seeing as it responds to the scroll settings set in System Preferences >> Appearance). It's not really drawing the scroller that's the issue, its just making it overlay the content.
Any advice is appreciated :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在此处设置滚动条的自定义类。
之后,通过覆盖
方法,您将正确放置它们。NSScrollView
的 -tileHere's where you can set the custom class of your scrollbars.
After that, by overriding the
-tile
method ofNSScrollView
, you'll get them placed properly.这是我的解决方案:
创建一个扩展 NSScroller 的 MyScroller 类
在 MyScroller.m 中
:然后只需在 Interface Builder 中为 Scroller 设置自定义类即可。
Here is my solution :
Create a MyScroller class that extends NSScroller
In the MyScroller.m :
Then just set the custom class for the Scroller in Interface Builder.
我最近发布了 RFOverlayScrollView 应该可以解决您的问题:
来源:https://github.com/rheinfabrik/RFOverlayScrollView
博客文章:http://blog.rheinfabrik.de/blog /2013/01/01/介绍-rfoverlayscrollview/
I've recently released RFOverlayScrollView which should solve your problem:
Source: https://github.com/rheinfabrik/RFOverlayScrollView
Blog Post: http://blog.rheinfabrik.de/blog/2013/01/01/introducing-rfoverlayscrollview/
您可以将
NSScrollerView
控件上的scrollerStyle
更改为.overlay
以获得所需的叠加效果。这可能会否决系统设置中滚动条可见性的系统范围设置。要在应用运行时“幸存”滚动条设置更改,您必须观察
NSScroller.preferredScrollerStyleDidChangeNotification
并重新应用叠加效果。You can change the
scrollerStyle
over theNSScrollerView
control to.overlay
to get the desired overlay effect.This may overrule the system wide setting in System Settings for scroll bar visibility. To 'survive' scroll bar setting changes while your app is running, you must observe the
NSScroller.preferredScrollerStyleDidChangeNotification
and re-apply the overlay effect.