开发者

Location on screen of location in NSTextView

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 i开发者_如何学JAVAs 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜