NSPoint/NSRect 来自 NSTextView 中的字符
所以我试图获取与 NSTextView 中特定字符的位置相对应的 NSPoint 或 NSRect 。这就是我到目前为止所拥有的(效果不是很好,结果似乎有点不可预测。
NSRange theTextRange = [[theTextView layoutManager] glyphRangeForCharacterRange:[theTextStorage editedRange] actualCharacterRange:NULL];
NSRect theTextRect = [[theTextView layoutManager] boundingRectForGlyphRange:theTextRange inTextContainer:[theTextView textContainer]];
So I am trying to get either an NSPoint or NSRect corresponding with the location of a specific character in an NSTextView. This is what I have so far (that isn't working very well, the results seem kind of unpredictable.
NSRange theTextRange = [[theTextView layoutManager] glyphRangeForCharacterRange:[theTextStorage editedRange] actualCharacterRange:NULL];
NSRect theTextRect = [[theTextView layoutManager] boundingRectForGlyphRange:theTextRange inTextContainer:[theTextView textContainer]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
boundingRectForGlyphRange:inTextContainer:
返回的矩形位于容器坐标中。如果你想获得相对于文本视图的矩形,你需要对此进行调整:The rect returned by
boundingRectForGlyphRange:inTextContainer:
is in container coordinates. You need to adjust for this if you want to get the rect relative to the text view:您可以通过 NSPoint & 使用鼠标按下事件NS矩形
You can use mouse down event by NSPoint & NSRect