Hide the keyboard after entering the text box.

Source: Internet
Author: User

Hide the keyboard after entering the text box.

Two ways to hide a virtual keyboard

After entering information in the text box, hide the keyboard;

Two methods: the first one is to press the return key to hide the keyboard. The second is to press the blank area on the screen to hide the interface.

Implementation Method:

Method 1: Add Action to the text box, select Did End On Exit as the event type, and add logical code to the implementation method;

Method 2: To touch the background, first modify the background class. By default, UIView does not respond to the event and is changed to UIControl, which is its subclass. Then, add the action backgroupTap and set the event type to TouchDown;

The implementation code is as follows:

. H file added output port and action

-(IBAction) textDoneExiting :( UITextField *) sender;

@ Property (weak, nonatomic) IBOutletUITextField * txtName;

@ Property (weak, nonatomic) IBOutletUITextField * txtCode;

 

Added implementation logic to the. m file;

-(IBAction) textDoneExiting :( UITextField *) sender {

[Sender resignFirstResponder];

}

-(IBAction) backgroupTap :( UIControl *) sender {

Using self.txt NameresignFirstResponder];

[Self.txt CoderesignFirstResponder];

}

 

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.