UITextField calls resignFirstResponder to move down.
Two textfields are used in a View in the project. Because only the becomeFirstResponder method is set for one TextField, TextField is moved down when resignFirstResponder is called on the hidden keyboard, when the keyboard appears, it will return to the original position. The solution is to set becomeFirstResponder for both TexfField or none. The keyboard will appear by default. To avoid some bugs, do not set them as well. Hope to help you.
How can I use UITextFieldDelegate to hide the keyboard?
Three steps are required:
1. Add the UITextFieldDelegate protocol to your controller class, for example:
@ Interface EditingPersonViewController: UIViewController
2. Add the textFieldShouldReturn Method to the implementation file as required by the Protocol, for example:
-(BOOL) textFieldShouldReturn :( UITextField *) textField {
[TextField resignFirstResponder];
Return YES ;}
3. Direct the delegate variable of the TextField control in the xib file to the Controller class that used the UITextFieldDelegate protocol before, and right-click the delegate IBOutlet variable of the TextField to the instance of the previous controller class.
You can also use code to specify the delegate variable of the relevant TextField.
-(Void) viewDidLoad {
[Super viewDidLoad];
ItemNameField. delegate = self;
PriceField. delegate = self;
} The third step is easy to ignore. Previously, because you forgot to specify the delegate variable, you can click the return key on the keyboard. The keyboard remains hidden.
What is the resignFirstResponder?
First Responder: the control that the user is currently using to interact with, that is, the First Responder keyboard.
ResignFirst Responder: "trigger keyboard hiding" or "trigger keyboard disabling ".
On the iPhone interface, after entering the content, you often need to hide the keyboard. You can use resignFirstResponder and UITextFieldDelegate to hide the keyboard. Close the keyboard by touching the screen.
Q: Is this the status of canceling the first response or becoming the first response, which is different from that of becameFirstResponder?
A: The first response is canceled.