IOS7 several ways to hide the keyboard by clicking the Blank Space
iOS development often use the input box, by default, click on the input box will pop up the keyboard, but you must implement the input box to return the delegate method to cancel the keyboard display, for the user experience is very unfriendly, we can achieve click outside the keyboard blank area to hide the keyboard, Below I have summed up several ways to hide the keyboard:
Let's start by explaining two ways you can hide your keyboard:
1. [View endediting:YES] This method allows the entire view to cancel the first responder, thus allowing the keyboard of all controls to be hidden.
2, [textfiled Resignfirstresponder] This is more commonly used to let a textfiled keyboard hidden.
3. send Resignfirstresponder.
[[UIApplication sharedapplication] sendaction: @selector (resignfirstresponder) To:nil From:nil Forevent:nil];
Here are a few ways to achieve this:
The first: Use the view's Touchesbegan: Touch event to hide the keyboard, which triggers the event when the view area is clicked.
- -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{
- [View Resignfirstresponder];
- }
The second type: Create a custom touch gesture to hide the keyboard:
(Add gesture implementation one)
-(void) viewdidload
- {
- [Super Viewdidload];
- UITapGestureRecognizer *tapgesturerecognizer = [[UITapGestureRecognizer alloc] initwithtarget:self action:@ Selector (keyboardhide:)];
- Set to No to indicate that the current control is propagated to other controls when it responds, by default yes.
- Tapgesturerecognizer.cancelstouchesinview = NO;
- Add a touch event to the current view
- [Self.view Addgesturerecognizer:tapgesturerecognizer];
- }
- -(void) Keyboardhide: (uitapgesturerecognizer*) tap{
- [view Resignfirstresponder];
- }
(Add gesture Implementation II)
The soft keyboard can only be turned off by return too inflexible and should provide the ability to touch the background to hide the soft keyboard.
In storyboard, click Background view to set its custom class to Uicontrol so that the touch down event appears.
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. h file to create a way to handle the event.
Come to the. m file, fill in the specific code--
- -(Ibaction) View_touchdown: (ID) Sender {
- //Send Resignfirstresponder.
- [[UIApplication sharedapplication] sendaction: @selector (resignfirstresponder) To:nil From:nil Forevent:nil];
- }
The Third Kind: Modify the custom class of UIView in Xib to Uicontrol,uicontrol is a kind of common control such as UIButton's parent class, is UIView's derived class, implements the touch and the down-pressing encapsulation.
1, first set xib in the UIView custom class for Uicontrol
2, set the relationship event, drag the Xib UIView into the. h zone
Set the event to touch up Inside
3. Write Hidden code:
- -(Ibaction) TouchView: (ID) Sender {
- [Self.view Endediting:yes];
- }
Several ways to hide your keyboard in the empty space on IOS