Summarize three ways to hide soft keyboards in IOS _ios

Source: Internet
Author: User

One, use the soft keyboard of the done key to hide the keyboard

Starting soft keyboard Hiding the most commonly used event is the Did end of the text box, which occurs when the user presses the done key on the soft keyboard. Select a Uitextfield control, click the right mouse button to eject the panel, the left mouse button hold down the Did end of the event next to the circle, and then drag to the right. h file, named Closethekeyboard, in the M file in the implementation of the following figure (shown here). h files and. m files):

When there are many text boxes on the page, if you need a text box to activate the soft keyboard each time, enter and then click Return to hide the soft keyboard, and 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, for a login page. It has an account text box (Nametextfield), a Password text box (Passtextfield), a login button (LOGINBTN).
We hope--click on the Password text box soft keyboard return time to jump to the cipher text box, click on the Password text box soft keyboard return when performing login.
Because the two text boxes have different functions, you can't write a closethekeyboard as you did in the previous section, but you should build your own event-handling methods separately.

Go back to Storyboard, right-click the Account text box pop-up panel, hold down the circle next to the did end on the exit event, and then drag to the white space on the right. h file, a dialog box pops up to name the method. The input name (Closethekeyboard) is determined by carriage return, and the event method is generated automatically.

Then follow the same practice, the did end of the Password text box (Passtextfield) to the Exit Event connection method (Passwordtextfield).

For account text box 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 after the password text box return. Because you no longer need to display the soft keyboard, you still have to invoke resignfirstresponder to hide the soft keyboard, and then trigger the login button (LOGINBTN) UIControlEventTouchUpInside event to log on.

To run, we can find that we have achieved the desired effect. Click on the Account text box soft keyboard return time to jump to the Password text box, click on the Password text box soft keyboard return when performing login.

How all is "return", Convert text box and execute login clearly 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" so that the interface is consistent with the function.

Second, touch the background to hide soft keyboard (touching down event trigger)

In storyboard, click the background view, set its custom class to Uicontrol, so that the touch down event occurs. Right-click the background View pop-up panel, hold down the circle next to the touch down event, and then drag to the blank place on the right. h file to establish a method for handling the event.

Third, touch the background to hide the soft keyboard (through the background transparent large button trigger)

Drag the button control in the view library 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. Double-click the caption of the button control to delete it, hidekeyboard the button with the. h file, and associate the text box control of the user design interface with the socket variable MyTextField. The specific code is as follows:

Iv. Summary

The above is a summary of their own iOS hidden soft keyboard Three methods, follow-up will be collated some other techniques and methods, interested friends can continue to focus on the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.