简体   繁体   English

使用UITextView时如何隐藏键盘?

[英]How to hides the keyboard when we use the UITextView?

我正在开发一个应用程序。在这种情况下,我使用textview。但是,当我们单击textview或完成将文本输入到textview中时,不会触发textview委托方法。我也写了textview.delegate = self。但是它们没有触发所以请告诉我如何解决这个问题

The UITextViewDelegate methods do not handle dismissal of the keyboard: you must do that yourself, by calling: UITextViewDelegate方法不处理键盘的UITextViewDelegate :您必须自己执行以下操作:

[textView resignFirstResponder];

This will then trigger the textViewShouldEndEditing:(UITextView *)textView delegate method. 然后,这将触发textViewShouldEndEditing:(UITextView *)textView委托方法。 What you need to do is call the resignFirstResponder method in response to whatever actions you require - if this is tapping outside the text view you'll need to create a gesture recognizer / button / whatever to pick up that tap and call resignFirstResponder . 您需要做的是调用resignFirstResponder方法,以响应您需要执行的任何操作-如果在文本视图之外点击,则需要创建一个手势识别器/按钮/任何东西来拾取该点击并调用resignFirstResponder

You can also use Keyboard notifications like: 您还可以使用键盘通知,例如:

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(keyboardWillShow) 
    name:UIKeyboardWillShowNotification object:nil];

and in -(void) keyboardWillShow {} set [myTextField resignFirstResponder]; 并在-(void) keyboardWillShow {}设置[myTextField resignFirstResponder];

hope this helps. 希望这可以帮助。

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

相关问题 当键盘出现时,如何使UITextView可滚动? - How to make an UITextView scrollable when the keyboard appears? 如何在键盘出现时在iOS上调整UITextView的大小? - How to resize UITextView on iOS when a keyboard appears? 键盘隐藏时的iOS事件 - iOS event when keyboard hides 使用UITextView时如何对键盘的DONE按钮做出反应? - How to react on the DONE button of the keyboard when using a UITextView? 当键盘可见时,如何使UITextView一直滚动到底部 - How to make a UITextView scroll all the way to the bottom when the keyboard is visible 当键盘可见时,如何让UITextView正确滚动 - How do I get UITextView to scroll properly when the keyboard is visible 显示键盘时如何解决问题,键盘隐藏了标签栏 - how to solve issue when keyboard is getting displayed, keyboard hides the tab bar 如何获得键盘大小来调整UITextView的大小以及如何在日语键盘上使用UIKeyboardFrameEndUserInfoKey? - How to get keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard? 进入contenteditable时,iPhone键盘会隐藏文字 - iPhone keyboard hides text when entering on contenteditable 在UITextField上轻触时,IQKeyboardManager会隐藏键盘 - IQKeyboardManager hides keyboard when tapped on UITextField
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM