Transferred from: http://leopard168.blog.163.com/blog/static/168471844201422121310352/
In the iOS app, as long as you use the edit box (Uitextfield), you have to deal with the keyboard disappearing (dismiss keyboard). I have used 4 different methods to deal with the problem of keyboard disappearance. 1. Release the first responder (Resignfirstresponder) through Uitextfileddelegate, the code for releasing the keyboard via delegate is as follows:
-(BOOL) Textfieldshouldreturn:( Uitextfield *) TextField {
[TextField resignfirstresponder];
returnYES;
}
The following 3 ways are handled by responding to events:
2. Through the Didonexit method of the Done key, to Resignfirstresponder;
3. Click the background image of the edit box to make the keyboard disappear. Method: Set the background view to: Uicontroll. The UIView itself cannot respond to events, while Uicontroll can respond to events. Uicontroll inherits from UIView; makes the keyboard disappear by invoking the Touch-down event of Uicontroll;
4. Place a UIButton to make the UIButton full screen, and when you click on a non-editable area, click on the Giant button. In this button event, the Resignfirstresponder can be.
- (ibaction)backgroundtap:(ID) Sender {
[self. Nametextfield Resignfirstresponder ];
[self. Passwordtextfield Resignfirstresponder ];
}
Description: this Method simulates two behaviors of a user:
1. Click on the Done button on the keyboard to make the keyboard disappear;
2. Click outside the edit box to make the keyboard disappear.
Special Note: through full-screen Button , this method requires: this giant. Button be sure to put it at the bottom. Otherwise, the edit box will not accept the input events.
Program Reviews:
uitextfielddelegate and the Uicontroll program to deal with the keyboard disappearing problem, which is a great wisdom. and the giant Button and didonexit method, although can also use, but from the software programming thinking, can only be considered a kind of smart.
Summary:
whenever an input box exists, you have to deal with the problem of how to make the keyboard disappear. Of course, you can just handle clicking on the "done" button to make the keyboard disappear. However, in order for the user to have a better experience, you need to handle the event response of a zone that is not an edit box.