Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 在NSTextView中拖动插入符号不会';CharacterIndexFormPoint的t匹配结果_Cocoa - Fatal编程技术网

Cocoa 在NSTextView中拖动插入符号不会';CharacterIndexFormPoint的t匹配结果

Cocoa 在NSTextView中拖动插入符号不会';CharacterIndexFormPoint的t匹配结果,cocoa,Cocoa,我正在拖动到NSTextView上(从另一个窗口的表中),当我在NSTextView中的文本上拖动时,将显示一个插入符号,显示插入点。似乎无法获取此插入符号的位置,我正在使用: NSPoint mouseLocation = [sender draggingLocation]; NSPoint localMouseLocation = [self convertPoint:mouseLocation fromView:nil]; CGFloat fraction = 0.4; NSUIntege

我正在拖动到NSTextView上(从另一个窗口的表中),当我在NSTextView中的文本上拖动时,将显示一个插入符号,显示插入点。似乎无法获取此插入符号的位置,我正在使用:

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]];