Cocoa 在NSTextView中拖动插入符号不会';CharacterIndexFormPoint的t匹配结果
我正在拖动到NSTextView上(从另一个窗口的表中),当我在NSTextView中的文本上拖动时,将显示一个插入符号,显示插入点。似乎无法获取此插入符号的位置,我正在使用:Cocoa 在NSTextView中拖动插入符号不会';CharacterIndexFormPoint的t匹配结果,cocoa,Cocoa,我正在拖动到NSTextView上(从另一个窗口的表中),当我在NSTextView中的文本上拖动时,将显示一个插入符号,显示插入点。似乎无法获取此插入符号的位置,我正在使用: NSPoint mouseLocation = [sender draggingLocation]; NSPoint localMouseLocation = [self convertPoint:mouseLocation fromView:nil]; CGFloat fraction = 0.4; NSUIntege
NSPoint mouseLocation = [sender draggingLocation];
NSPoint localMouseLocation = [self convertPoint:mouseLocation fromView:nil];
CGFloat fraction = 0.4;
NSUInteger dropLocation = [[self layoutManager] characterIndexForPoint:localMouseLocation inTextContainer:[self textContainer] fractionOfDistanceBetweenInsertionPoints:&fraction];
问题是,有时插入的文本会在显示的插入符号左侧插入一个字符。我尝试了不同的“插入点之间距离的分段”值,但没有成功
问题1。有没有办法获得拖动插入符号的位置
问题2。苹果使用的“插入点之间距离的分位数”值是多少
第三季度。我是否应该使用另一种方法(drawInsertionPointInRect)
谢谢。好的,解决方案是使用characterindexforinsertionPoint而不是characterIndexForPoint。因此
NSPoint mouseLocation = [sender draggingLocation];
NSUInteger dropLocation = [self characterIndexForInsertionAtPoint:[self convertPoint:mouseLocation fromView:nil]];