NSScrollView 滚动位置
我目前在 NSScrollView 中有一个 NSView。 NSView 很大,我需要滚动来管理里面的对象。
我想在 NSView 的中心绘制一个静态矩形而不滚动。 我想在NSView的drawRect方法中获取滚动点(NSClipPoint?),以便我可以在drawRect的最后一步绘制矩形,使其位于顶部。
我浏览了文档,只能找到设置滚动点的方法,但没有找到它。 我怎样才能得到这一点?
I currently have a NSView in a NSScrollView.
The NSView is large and I need to scroll to manage the object inside.
I want to draw a static rectangle in the center of the NSView without scrolling.
I want to get the scrolling point (the NSClipPoint?) in the drawRect method of the NSView so that I can draw the rectangle at the last step of drawRect to make it on top.
I have looked through the doc and could only find methods to set the scroll point, not getting it.
How can I get that point?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是
[[myScrollView contentView] documentVisibleRect]
The answer is
[[myScrollView contentView] documentVisibleRect]
我从未尝试过这个,所以我不知道它是否真的有效(而且我距离 Mac 大约有 8 个小时的路程,所以我无法尝试)。但是你可以子类化你的 NSScrollView 正在使用的 NSClipView 并在 NSClipView 的 drawRect: 中绘制矩形吗?如果这不起作用,直接用 NSScrollView 尝试同样的事情怎么样?
如果这不起作用,呃...报告回来,我会删除这个答案,以免误导来自谷歌的任何人。 :)
I've never tried this, so I don't know if it will actually work or not (and I'm about 8 hours away from my Mac, so I can't give it a shot). But can you subclass the NSClipView that your NSScrollView is using and draw the rectangle in NSClipView's drawRect:? If that doesn't work, what about trying the same thing with the NSScrollView directly?
And if that doesn't work, er...report back and I'll remove this answer so as not to mislead anyone coming from Google. :)