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]; }