IOS makes the keyboard disappear

Source: Internet
Author: User
Tags uicontrol

IOS makes the keyboard disappear

Some text input controls will pop up when waiting for input, you can set the Did End On Exit callback method of these controls to collapse the keyboard when you click the button in the done or return column On the soft keyboard.

However, sometimes the keyboard does not have the above buttons, or we want to enable the keyboard to be closed when we click the background of the App view, whether or not the keyboard is opened at that time.

One way is to drag a button to the View, make it the same size as the View, and set the callback for clicking this button.

But, we can also have a simpler method.

We know that UIView has no Action, but its sub-class UIControl has many, so we can change the View type from UIView to UIControl, in this way, we can get the desired touch event for free, so the first step is to change the View class to UIControl:

Vc23zsS8/izRodTxysK8/rsmwo%9zo8l3a + DQo8cD48aW1nIGFsdD0 = "Write picture description here" src = "http://www.bkjia.com/uploads/allimg/160226/04155C936-1.png" title = "\"/>

Finally, we completed the compilation of the callback method:

-(IBAction) bgTaped :( id) sender {[_ text resignFirstResponder];}

Through the above steps, we have completed the functions we want ;)

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.