2

I have UITextView subclass with no keyboard, that use buttons for input. I want to allow move cursor by tap to any position, not only to start or end of word. That's how it's works now:

enter image description here

enter image description here

That's what I want:

enter image description here

I think that solution for this problem is quite complex for beginner, so I ask you for a bit more detailed description how to do it.

I have found this but dont know where should I use this part of code.


Here is solution:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event];
    UITouch *userTouch = [[event allTouches] anyObject];
    CGPoint currentPos = [userTouch locationInView:self];
    UITextPosition *cursorPosition=[self closestPositionToPoint:CGPointMake(currentPos.x, currentPos.y)];
    [self setSelectedTextRange:[self textRangeFromPosition:cursorPosition toPosition:cursorPosition]];
}
Community
  • 1
  • 1
Konstantin Cherkasov
  • 3,243
  • 2
  • 18
  • 22

0 Answers0