![](/img/trans.png)
[英]NSLayoutManager: Calling setLocation:forStartOfGlyphRange: does not change the position of the drawn glyph
[英]Get right point of glyph in NSLayoutManager with linebreak-mode enabled
我正在嘗試獲取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)
}
它可以正常工作,直到由TIL設置的第一個換行符
NSParagraphStyle.hyphenationFactor = 2
每個連字符將索引移動一個點,並且glyphIndexForPoint
獲取錯誤的索引。 如何在啟用換行模式的情況下獲取正確的索引?
嘗試使用類似的功能characterIndexForPoint(_:inTextContainer:fractionOfDistanceBetweenInsertionPoints :)
有關更多詳細信息,您可以看到此問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.