パン ジェスチャで UITextfield のカーソルを移動しようとしています。しかし、私はいくつかの問題に直面しています。
UITextfield と UIView (同じサイズの UITextfield) があります。
UIViewで指をドラッグしてUITextfieldのカーソル位置を移動したいので、UIViewにパンジェスチャを追加しました
しかし、カーソル位置を移動していて、カーソルが UITextfield の隅に来ると、テキストのスクロールは行われません。
誰でもこの問題を解決するのを手伝ってもらえますか?
コード :
-(void)panGesture:(UIPanGestureRecognizer *)pan
{
CGPoint translation = [pan translationInView:btnMove];
CGPoint vel = [pan velocityInView:btnMove];
UITextRange *range = txtSearch.selectedTextRange;
NSInteger endOffset = [txtSearch offsetFromPosition:txtSearch.beginningOfDocument toPosition:range.end];
if (vel.x > 0)
{
endOffset = endOffset + 1;
NSLog(@"right - %ld",(long)endOffset);
}
else{
endOffset = endOffset - 1;
NSLog(@"left - %ld",(long)endOffset);
}
UITextPosition *from = [txtSearch positionFromPosition:[txtSearch beginningOfDocument] offset:endOffset];
UITextPosition *to = [txtSearch positionFromPosition:[txtSearch beginningOfDocument] offset:endOffset];
txtSearch.selectedTextRange = [txtSearch textRangeFromPosition:from toPosition:to];
}