NSTextView 中位置在屏幕上的位置
我想获取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 文档,字形的位置相对于其封闭的行片段。您应该使用线片段的矩形来调整点。这应该可以解决您看到的变化。
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.