NSTextView 中位置在屏幕上的位置

发布于 2024-08-21 06:37:09 字数 366 浏览 5 评论 0原文

我想获取 NSTextView 中某个点的屏幕位置(NSPoint),这应该很简单,但结果总是有点偏差,X 是完美的,但 Y 似乎有所不同。

我尝试了下面代码的一些变体,但无法得到我想要的结果,NSClipView 是否搞砸了?

NSPoint p = [[self layoutManager] locationForGlyphAtIndex:r.location];
//NSPoint b= [self convertPoint:p toView:nil];
NSPoint screenlocation = [self convertPointToBase:p];

有什么想法吗?

干杯!

公吨

I want to get the screen location (NSPoint) of a point in an NSTextView, this should be simple, but by results are always a bit off, the X is perfect, but the Y seems to vary.

I've tried a few variations of the code below, but can't get the result I'm after, is the NSClipView screwing it up?

NSPoint p = [[self layoutManager] locationForGlyphAtIndex:r.location];
//NSPoint b= [self convertPoint:p toView:nil];
NSPoint screenlocation = [self convertPointToBase:p];

Any ideas?

Cheers!

MT

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

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

发布评论

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

评论(1

草莓味的萝莉 2024-08-28 06:37:09

According to the documentation, the location for a glyph is relative to its enclosing line fragment. You should adjust the point by using the rectangle of the line fragment. That should fix the variation you see.

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