入力にボタンを使用する、キーボードのない UITextView サブクラスがあります。単語の先頭または末尾だけでなく、タップで任意の位置にカーソルを移動できるようにしたい。それが今の仕組みです:
それが私が欲しいものです:
この問題の解決策は初心者にはかなり複雑だと思うので、もう少し詳しい方法を教えてください。
これを見つけました が、コードのこの部分をどこで使用すればよいかわかりません。
ここに解決策があります:
- (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]];
}