NSScrollview 和透明、覆盖 NSScroller 子类
我制作了一个光滑的 NSScroller 子类,但不知道如何使其覆盖在 NSScrollView 之上,而不是推送 documentView放在一边。
在这里您可以看到我希望将其设为 100 的 NSCollectionView
的背景% 宽,并让滚动条位于顶部。目前,我必须为滚动条设置白色背景,因为使用 clearColor
进行绘制不会显示为透明,而是显示为黑色。
我是否以错误的方式处理这个问题?我在这里遗漏了一些明显的东西吗?如何实现位于 NSScrollView
内容之上的透明跟踪 NSScroller
的行为?
I have made a slick NSScroller
subclass, but can't figure out how to make it overlay on top of the NSScrollView
instead of pushing the documentView
aside.
Here you can see the background of a NSCollectionView
that I wish to make 100% wide, and have the scroller sit along top. Currently, I have to set a white background to the scroller because drawing with a clearColor
is not showing as transparent, but as black.
Am I going about this the wrong way? Am I missing something obvious here? How can I achieve the behavior of a transparent-tracked NSScroller
that sits atop a NSScrollView
's contents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够通过在子类 OF NSSCROLLVIEW 中实现
tile
来获得定位,事实证明,尝试绘制清晰的颜色是一开始的问题。在滚动器子类中,我只是完全省略了与滑块轨道有关的任何绘图 通过重写 NSSCROLLER 子类的
DRAWRECT:
,如下所示:I was able to get the positioning by implementing
tile
in the subclass OF NSSCROLLVIEWAnd it turns out that trying to draw clear color was the problem to begin with. In the scroller subclass, I just omitted any drawing that had to do with the slider track completely BY OVERRIDING
DRAWRECT:
OF THE NSSCROLLER SUBCLASS, LIKE SO:请注意,要使其正常工作,您必须为滚动视图启用图层支持!
即调用:
或者在Interface Builder中设置。
如果不这样做,scrollView 的 contentView 将绘制在滚动条的顶部。另外:你应该意识到你所做的本质上是重叠两个 NSView(NSScroller 位于 NSScrollView 之上——两者都继承自 NSView。)与 iOS 上的 UIView 不同,OS X 上的重叠 NSView 不受任何当前版本的正式支持操作系统(10.6 以下)。打开 CALayers 似乎可以使其工作,但这仍然是需要记住的事情。当然,打开图层会严重降低绘图性能。
有关更多详细信息,请参阅此问题: 是否有合适的处理重叠 NSView 兄弟姐妹的方法?
Note that for this to work properly, you MUST enable layer-backing for the scrollView!
That is, call:
or set it in Interface Builder.
If you don't do this, the scrollView's contentView will draw ON TOP OF the scrollers. Also: you should be aware that what you're doing is essentially overlapping two NSViews (NSScroller on top of NSScrollView --- both inherit from NSView.) Unlike UIViews on iOS, overlapping NSViews on OS X is not officially supported by any current version of the OS (10.6 down). Turning on CALayers seems to make it work, but it's still something to bear in mind. Of course, turning on layers can seriously kill drawing performance.
See this SO question for more detail: Is there a proper way to handle overlapping NSView siblings?
这个颜色是什么:
[NSColor colorWithCaliberatedRed:0.0 green:0.0 blue:0.0 alpha:0.0]
我认为你必须使用界面生成器修改尺寸。
What's about this color:
[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.0]
I think you have to modify the sizes with the interface builder.