2

入力にボタンを使用する、キーボードのない 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]];
}
4

0 に答える 0