将UITextView光标移动到CGPoint [英] Moving UITextView cursor to a CGPoint

查看:320
本文介绍了将UITextView光标移动到CGPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 UITextView 的行为方式与Notes中的一样,即点击使其可编辑(关闭数据检测器),然后光标移动到

Am trying to make a UITextView behave the way the one in Notes does, i.e. you tap to make it editable (turning off the data detectors) then the cursor moves to where you tapped.

点击编辑部分使用 UITapGestureRecognizer 工作,但在地球上您将轻敲的 CGPoint 翻译成 NSRange 以移动光标?

Got the tap-to-edit part working with a UITapGestureRecognizer, but how on earth do you translate the tap's CGPoint into a NSRange for moving the cursor?

我没有这样做的奢侈在5.0(没有 UITextInput UITextView ,ack )。
也需要是public API,没有私人的东西。

I don't have the luxury of doing this under 5.0 (no UITextInput for the UITextView, ack). Also needs to be public API's, no private stuff.

提前感谢。 :)

推荐答案

UITextPosition * position=[textView closestPositionToPoint:CGPointMake(20, 20)];
[textView setSelectedTextRange:[textView textRangeFromPosition:position toPosition:position]];

这篇关于将UITextView光标移动到CGPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆