Moving UITextView cursor to a CGPoint

别等时光非礼了梦想. 提交于 2019-12-24 15:41:38

问题


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.

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?

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.

Thanks in advance. :)


回答1:


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


来源:https://stackoverflow.com/questions/9338951/moving-uitextview-cursor-to-a-cgpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!