gpt4 book ai didi

ios - 插入符在 UI​​TextView 和 Text Kit 中的长按空白处消失

转载 作者:行者123 更新时间:2023-11-29 13:02:22 27 4
gpt4 key购买 nike

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

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

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

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

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

最佳答案

找到解决方案。

子类化 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;
}

关于ios - 插入符在 UI​​TextView 和 Text Kit 中的长按空白处消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19463893/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com