6

我似乎找不到任何有关如何获取插入点矩形的文档。我正在尝试在文本插入符号/插入点正下方显示一个视图(如自动完成)

我正在考虑制作一个自定义文本视图,但如果我可以避免它,那在我的情况下将是理想的。谢谢!

4

1 回答 1

7
- (NSRect)rectForActiveRange {
    NSLayoutManager *l = [self layoutManager];
    NSRange range = [l glyphRangeForCharacterRange:self.activeRange actualCharacterRange:nil];
    NSRect rect = [l boundingRectForGlyphRange:range inTextContainer:[self textContainer]];
    rect = NSOffsetRect(rect, self.textContainerOrigin.x, self.textContainerOrigin.y);
    return rect;
}

activeRange == selectedRange WHICH 是选择范围,或者如果有选择,则从您键入的右侧开始长度为 0 的范围

另见: http: //www.cocoabuilder.com/archive/cocoa/158706-how-to-find-the-insertion-point-of-nstextview.html

于 2013-05-05T17:49:21.067 回答