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.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论