我想知道当我们长按UITextfield或UITextview来移动光标时会触发哪个委托方法?请帮帮我。
答案 0 :(得分:1)
没有合适的UITextField委托来检测光标移动。
使用UITextView时,您可以使用textViewDidChangeSelection:
,请参阅here。
答案 1 :(得分:1)
您应该为此目的使用手势识别器
1)首先将识别器添加到TextFiled
**-(void)viewDidLoad{**
UILongPressGestureRecognizer *recognizerTextFiled = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandlerGurmukhiFirstSearch:)];
recognizerTextFiled.minimumPressDuration = 0.5;
//after this time Recognizer will invoke
// here i have added the Recognizer to that textField
// myTextFiled is a textField at which we want to detect the cursor movement
[myTextFiled addGestureRecognizer:recognizerTextFiled];
[recognizerTextFiled release];
}
2)您可以在检测到光标移动如下
后编写逻辑**-(void)longPressHandlerGurmukhiFirstSearch:(UILongPressGestureRecognizer *)gestureRecognizer**
{
if(UIGestureRecognizerStateBegan ==gestureRecognizer.state)
{
// you can write the code here as you want for moving the Cursor
}
if(UIGestureRecognizerStateChanged == gestureRecognizer.state) {
// Do repeated work here (repeats continuously) while finger is down
}
if(UIGestureRecognizerStateEnded == gestureRecognizer.state) {
// Do end work here when finger is lifted
}
}
}
我希望这可以帮助您检测 UITextField
上的光标移动