IOS Development in the soft keyboard is a frequent need to deal with the place, below for everyone to bring me to summarize the 3 ways to hide the keyboard.
- Use the soft keyboard 's done key to hide the keyboard
Departure Soft keyboard Hide the most commonly used event is the did Endof the text box on Exit, which occurs when the user presses the done key in the soft keyboard. Select a Uitextfield control, click the right mouse button to eject the panel, the left mouse button hold down the circle next to the Do End on Exit event, and then drag to the right. h file, named Closethekeyboard, in M The specific implementation in the file is as shown in the. h file and the. m file shown here:
When there are many text boxes in the page, if you need a text box each time to activate the soft keyboard, enter and click Return to hide the soft keyboard, then click the next text box ... This is too cumbersome to operate. So we want to be able to automatically go to the next text box when we click Return. Especially for the last text box, you want to be able to do the next step when you click Return.
For example, the login page. It has an account text box (Nametextfield), a Password text box (Passtextfield), and a login button (LOGINBTN).
We hope--click on the return of the Account text box soft keyboard to jump to the Password text box, click on the Password text box soft keyboard return when you perform a login.
Because the functions of the two text boxes are different, it is not possible to write a closethekeyboard as in the previous section, but to set up separate event handling methods.
Go back to Storyboard, right-click the account TextBox flyout, press and hold the circle next to the Do End on Exit event, and then drag to the right. h file, and a dialog box pops up to give the method a name. After entering the name (Closethekeyboard), enter OK and the event method is automatically generated.
Then follow the same procedure for the Do End on Exit Event connection method (Passwordtextfield) for the Password text box (Passtextfield).
For the Account text box to the Password text box, do not need to hide the soft keyboard, just call Becomefirstresponder to activate the new text box on the line.
Perform a login for the password text box after return. Because the soft keyboard is no longer needed, it is still necessary to call Resignfirstresponder to hide the soft keyboard and then trigger the login button (LOGINBTN) UIControlEventTouchUpInside event to log in.
Run, and you can see that we have achieved the desired effect. Click on the return of the soft keyboard of the Account text box to jump to the Password text box, click on the Password text box soft keyboard return when you perform a login.
How is "Return", convert text box and execute login obviously is different function?
The return key property of the Account text box is set to "Next" and the return key property of the Password text box is set to "done" to make the interface consistent with the function.
- Touch Background Hide soft keyboard (touch down event Trigger)
In storyboard, click Background view to set its custom class to Uicontrol so that the touch down event appears. Right-click the background View pop-up panel, press and hold the circle next to the touch down event, and then drag to the right. h file to create a way to handle the event.
- Touch the background to hide the soft keyboard (triggered by a large background transparent button)
Drag the button control in the View Gallery to the design interface to resize the button control so that it can cover the entire design interface. Select editor| in the menu bar arrange| Send to back command to place the Button control behind all controls. The button control's caption is deleted by double-clicking it, the Hidekeyboard action is associated with the. h file, and the text box control of the user-designed interface is associated with the socket variable MyTextField. Specific code such as:
The above is their own summary of the iOS hidden soft keyboard 3 ways, follow-up will be a number of other techniques and methods, please pay attention!
3 Ways to hide a soft keyboard from IOS