iOS developing hidden keyboard methods Summary

Source: Internet
Author: User

Here are some of the ways that I've summarized several hidden keyboards.

First, hide their own soft keyboard

When there are multiple Uitextfield controls that want to hide their soft keyboard by clicking "Return", the best way to do this is to use the Do End on Exit event. This event is triggered when you click the "Return" button in the lower-right corner of the soft keyboard.


The event has a sender reference that represents the current text box so that it can write a common event-handling method (. m file)

  
 
  1. -(Ibaction) Textfield_didendonexit: (ID) Sender {
  2. //Hide keyboard.  
  3. [Sender Resignfirstresponder];
  4. }

Then fill in the. h file with the declaration of the Method--

 
   
  
  1. -  ( ibaction) Textfield_didendonexit: (ID) sender; 

Go back to Storyboard, and press Command+option+enter to open the secondary form so that the secondary form displays the. h file.

Select a Uitextfield control, click the right mouse button pop-up panel, the left mouse button hold the circle next to the Do End on Exit event, and then drag to the right side. h file on the Textfield_didendonexit method, the event connection is established.

Then follow the same procedure. The Do End on Exit event for other Uitextfield controls is also connected to the Textfield_didendonexit method.

You can see that the soft keyboard of each text box can be hidden by clicking "Return".

Second, click Return to take the initiative to go to the next text box

When there are more than one text box in the page, assume that each time you need a text box to activate the soft keyboard, enter and 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 click Return to take the initiative to go to the next text box.

Especially for the last text box. Hopefully, you can run the next action 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 (Loginbutton).
We want to---click the return of the Account text box soft keyboard to jump to the password text box. Click the return of the Password text box soft keyboard to run the login.
Because the functions of these two text boxes are different, it is not possible to write a textfield_didendonexit in the same way as in the previous section, but to establish the respective event handling methods separately.

Back to Storyboard, right-click the Account text box (Nametextfield) popup panel. Press and hold the circle next to the Do End on Exit event. Then drag to a blank place on the right side of the. h file, and a dialog box will pop up to give the method a name.

After entering the name (nametextfield_didendonexit), enter OK and the event method is generated on its own initiative.
Then follow the same procedure. The Do End on Exit Event connection method (Passtextfield_didendonexit) for the Password text box (Passtextfield).


Came to the. m file. Fill in the detailed code--

  
 
  1. -(Ibaction) Nametextfield_didendonexit: (ID) Sender {
  2. //Move focus to the next text box.  
  3. [Self.passtextfield Becomefirstresponder];
  4. }
  5. -(Ibaction) Passtextfield_didendonexit: (ID) Sender {
  6. //Hide keyboard.  
  7. [Sender Resignfirstresponder];
  8. //Trigger the Click event of the login button.  
  9. [Self.loginbutton Sendactionsforcontrolevents:uicontroleventtouchupinside];
  10. }

There is no need to hide the soft keyboard for the Account text box to go to the Password text box. Just call Becomefirstresponder to activate the new text box.


Run the login for the password text box after return. Because the soft keyboard is no longer needed. So you still have to call Resignfirstresponder to hide the soft keyboard and then trigger the login button (Loginbutton) UIControlEventTouchUpInside event to log in.

Execution, we can find that we have achieved the desired effect. Click Return on the soft keyboard of the Account text box to jump to the password text box. Click the return of the Password text box soft keyboard to perform a login.
How is "Return", convert text box and run login obviously is different function?
The return key property of the Account text box is then set to "Next". Set the Return key property of the Password text box to "done". Make the interface and function consistent.

Third, touch the background to hide the soft keyboard

Simply turning off the soft keyboard by return is too inflexible and should provide the ability to touch the background to hide the soft keyboard.

In storyboard, click Background View. Set its custom class to Uicontrol. This will cause the touch down event to occur.
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 side. h file to create a way to handle the event.


Came to the. m file. Fill in the detailed code--

  
 
  1. -(Ibaction) View_touchdown: (ID) Sender {
  2. //Send Resignfirstresponder.  
  3. [[UIApplication sharedapplication] sendaction: @selector (resignfirstresponder) To:nil From:nil Forevent:nil];
  4. }

Share these methods with people hoping to help their readers.


iOS developing hidden keyboard methods Summary

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.