【问题标题】:Caret disappears on long pressing blank space in UITextView and Text Kit插入符号在 UITextView 和 Text Kit 中的长按空白处消失
【发布时间】:2013-10-19 08:06:21
【问题描述】:
【问题讨论】:
标签:
ios
ios7
uitextview
textkit
【解决方案1】:
找到了解决办法。
继承 UITextView 并添加以下内容:
- (UITextPosition *)closestPositionToPoint:(CGPoint)point
{
point.y -= self.textContainerInset.top;
point.x -= self.textContainerInset.left;
CGFloat fraction = 1;
NSUInteger glyphIndex = [self.layoutManager glyphIndexForPoint:point inTextContainer:self.textContainer fractionOfDistanceThroughGlyph:&fraction];
NSInteger index = glyphIndex;
if (![[self.text substringFromIndex:self.text.length - 1] isEqualToString:@"\n"]) {
if (index == [self.text length] - 1 && roundf(fraction) > 0) {
index++;
}
}
NSUInteger characterIndex = [self.layoutManager characterIndexForGlyphAtIndex:index];
UITextPosition *pos = [self positionFromPosition:self.beginningOfDocument offset:characterIndex];
return pos;
}