For IOS developers, there are several ways to hide the virtual keyboard in the blank space:

Source: Internet
Author: User
Tags uicontrol

For IOS developers, there are several ways to hide the virtual keyboard in the blank space:
Input boxes are often used in OS development. By default, the keyboard will pop up when you click the input box. However, you must implement the delegate method of the input box return to cancel the display of the keyboard, which is unfriendly to the user experience, you can click a blank area outside the keyboard to hide the keyboard. Below I have summarized several methods to hide the keyboard:


The following two methods can be used to hide the keyboard:
1. [view endEditing: YES] This method can cancel the first responder of the entire view and hide the keyboard of all controls.
2. [textFiled resignFirstResponder] This is a commonly used method to hide a textFiled keyboard.


There are several implementation methods:

First, use the touchesBegan: Touch event of the view to hide the keyboard. This event is triggered when you click the view area.

 

 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{      [textFiled resignFirstResponder];  }  

Type 2: create a custom touch gesture to hide the keyboard:

 

 

-(Void) viewDidLoad {[super viewDidLoad]; UITap * tap = [[UITap alloc] initWithTarget: self action: @ selector (keyboardHide :)]; // set "NO" to indicate that the current control will be propagated to other controls after response. The default value is "YES. Tap. cancelsTouchesInView = NO; // Add the touch event to the current view [self. view addGestureRecognizer: tapGestureRecognizer];}-(void) keyboardHide :( UITap *) tap {[textFiled resignFirstResponder];}

Third, modify the Custom class of UIView in xib to UIControl. UIControl is a common control, such as the parent class of UIButton. It is a derived class of UIView and encapsulates the touch and down presses.
1. First, set the Custom class of UIView in xib to UIControl.


2. Set link events and drag the UIView in xib to. h.
Set the event to Touch Up Inside

 


3. Compile the hidden code:
 

- (IBAction)touchView:(id)sender {       [self.view endEditing:YES];  }  




 

 

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.