gpt4 book ai didi

ios - 如何将UITextView的光标移动到TOUCHED LOCATION?

转载 作者:行者123 更新时间:2023-12-01 16:25:45 25 4
gpt4 key购买 nike

我的问题的目的是使笔记应用程序像iOS一样。
iOS的note应用程序的要点是,它们提供给用户以使用 super 链接或电话号码链接或电子邮件地址作为蓝色textcolor,我们可以同时编辑文本。

通常,当我们按下UITextView时,它将光标定位到我们触摸的位置。但是,如果我使用UITextView的dataDetectorTypes放置电话号码或iOS记事应用之类的http链接之类的东西,则应将其设置为不可编辑,否则链接将不起作用。
这意味着我无法单击UITextView和“编辑文本”。

但是我可以使用下面的代码将其设置为可编辑

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
action:@selector(editTextRecognizerTabbed:)];

--
- (BOOL) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer
{
textview.editable = YES;
textview.dataDetectorTypes = UIDataDetectorTypeNone;
[textview becomeFirstResponder];
}

现在我可以编辑文本,并且一切正常,但是问题在于它总是以文本结尾开始,因此用户应再次轻按想要书写的位置。我知道原因。

现在,我想将光标移动到第一点所按的位置,并通过使用[aRecognizer locationInView:view]获得坐标。

那么如何将UITextView中的游标移动到我从识别器获得的位置?

谢谢。

最佳答案

- (void) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer
{
if (aRecognizer.state==UIGestureRecognizerStateEnded)
{
//Not sure if you need all this, but just carrying it forward from your code snippet
textview.editable = YES;
textview.dataDetectorTypes = UIDataDetectorTypeNone;
[textview becomeFirstResponder];

//Consider replacing self.view here with whatever view you want the point within
CGPoint point = [aRecognizer locationInView:self.view];
UITextPosition * position=[textView closestPositionToPoint:point];
[textView setSelectedTextRange:[textView textRangeFromPosition:position toPosition:position]];
}
}

关于ios - 如何将UITextView的光标移动到TOUCHED LOCATION?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35472882/

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