1

我正在使用 Text Kit 在文本视图上呈现一些富文本。

我的问题是 iOS 7 中似乎存在插入符号放置的错误。每当您长按文本视图中的空白区域时,插入符号似乎会消失,并且不会出现带有(剪切、复制、选择等)的弹出菜单。

您可以通过观看这个短片更好地理解这个问题:http: //cl.ly/1E0s2A2S0t2t

您可以通过从 Apple 下载 IntroToTextKit 示例代码自行尝试。这是该项目的链接: http: //cl.ly/0h0T0V1Z0D3H

对此的任何解决方法将不胜感激。

4

1 回答 1

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;
}
于 2013-10-19T15:56:26.473 回答