Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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
Ios 在启用换行模式的情况下,在NSLayoutManager中获取图示符的正确点_Ios_Swift_Nstextcontainer_Nsparagraphstyle - Fatal编程技术网

Ios 在启用换行模式的情况下,在NSLayoutManager中获取图示符的正确点

Ios 在启用换行模式的情况下,在NSLayoutManager中获取图示符的正确点,ios,swift,nstextcontainer,nsparagraphstyle,Ios,Swift,Nstextcontainer,Nsparagraphstyle,我正在尝试在NSTextContainer中获取所选字符的实际点: func handleTouch(gestureRecognizer: UIGestureRecognizer) { var location = gestureRecognizer.locationInView(self) let startPoint = self.layoutManager.locationForGlyphAtIndex(0) location = CGPoint(x: location.

我正在尝试在
NSTextContainer
中获取所选字符的实际点:

func handleTouch(gestureRecognizer: UIGestureRecognizer) {
   var location = gestureRecognizer.locationInView(self)
   let startPoint = self.layoutManager.locationForGlyphAtIndex(0)
   location = CGPoint(x: location.x - startPoint.x, y: location.y - startPoint.y)
   var fraction: CGFloat = 0
   let index = self.layoutManager.glyphIndexForPoint(location, inTextContainer: textContainer, fractionOfDistanceThroughGlyph: &fraction)
}
它可以正常工作,直到设置了第一个换行符

NSParagraphStyle.hyphenationFactor = 2
每个连字符将索引移动一个点,然后
glyphIndexForPoint
得到错误的索引。如何在启用换行模式的情况下获得正确的索引?

尝试类似的功能

有关更多详细信息,请参见此功能,并尝试使用类似的功能

有关更多详细信息,请参见此