简体   繁体   English

在UITextfield或UITextview中会触发哪种委托方法?

[英]Which delegate method will get fired in UITextfield or UITextview?

I want to know which delegate method will get fired when we long press the UITextfield or UITextview to move the cursor? 我想知道当我们长按UITextfield或UITextview移动光标时会触发哪个委托方法? Please help me out. 请帮帮我。

There is no suitable UITextField delegate for detecting cursor movements. 没有合适的UITextField委托来检测光标移动。

You may be able to use textViewDidChangeSelection: when working with a UITextView, see here . 您可以使用textViewDidChangeSelection:使用UITextView时,请参阅此处

You should use the Gesture Recognizer for this purpose 您应该使用手势识别器来实现此目的

1)Firstly Add Recognizer to your TextFiled 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) You may Write Your Logic after detecting the Cursor Movement As Below 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
        }
    }
}

I Hope This would help you to detecting the cursor movement over UITextField 我希望这可以帮助您检测UITextField上的光标移动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有一种方法可以使UITextView具有类似UITextField框的类似周围阴影? - Is there a method to get a UITextView with similar surrounding shadow like a UITextField box? 不使用resing键盘将调用哪个UITextField委托方法? - Which UITextField delegate method will be called without resing keyboard? 如何向 UITextField & UITextView 添加方法? - How to add a method to UITextField & UITextView? 如何获取当前活动的UITextField / UITextView和resignFirstResponder? - How to get the currently active UITextField/UITextView and resignFirstResponder? 用户在UITextView中输入两次调用委托方法? - User input in UITextView call delegate method twice? webview委托方法未在后台进程中触发 - webview delegate method is not fired in background process 如何在uitextfield委托方法中获取单元格索引路径? - How to get cell indexpath in uitextfield Delegate Methods? 使用UITextField和UITextView时textFieldShouldReturn方法的问题 - Problem with textFieldShouldReturn method when using UITextField along with UITextView 选择UITableViewCell而不是UITextView失去了调用didSelectRowAtIndexPath委托方法的能力? - Select the UITableViewCell over the UITextView losing ability to call didSelectRowAtIndexPath Delegate Method? 在UITextView委托方法中发现泄漏。 对解决方案感到困惑 - Spotted a leak in UITextView delegate method. Confused about solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM