Detailed IOS click on the blank space to hide the keyboard several ways to introduce _ios

Source: Internet
Author: User
Tags uicontrol

IOS7 Click on the blanks to hide the keyboard in several ways, as follows:

iOS development often use the input box, by default, click the input box will eject the keyboard, but must implement the input box return delegate method to cancel the keyboard display, for the user experience is very unfriendly, we can click on the keyboard outside the blank area to hide the keyboard, I've summed up several ways to hide the keyboard below:

First, there are two ways that you can hide the keyboard:

1. [View Endediting:yes] This method allows the entire view to cancel the first responder so that the keyboard of all controls is hidden.

2, [textfiled Resignfirstresponder] This is more commonly used to let a textfiled keyboard hidden.

Then there are several ways to implement it:

The first: using View's Touchesbegan: Touch events to achieve the hidden keyboard, when clicked View area will trigger this event

-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{ 
  [textfiled Resignfirstresponder]; 

The second type: Create a custom touch gesture to hide the keyboard:

-(void) viewdidload 
{ 
  [super viewdidload]; 
  UITapGestureRecognizer *tapgesturerecognizer = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector ( Keyboardhide:)]; 
  Setting to no indicates that the current control will propagate to other controls when it responds, and the default is yes. 
  Tapgesturerecognizer.cancelstouchesinview = NO; 
  Add a touch event to the current view 
  [Self.view Addgesturerecognizer:tapgesturerecognizer]; 
} 
 
-(void) Keyboardhide: (uitapgesturerecognizer*) tap{ 
  [textfiled resignfirstresponder]; 
} 

The Third: Modify xib UIView custom class for Uicontrol,uicontrol is a common control such as UIButton's parent class, a derived class of uiview that implements the encapsulation of touch and down.

1, first set the Xib UIView custom class for Uicontrol

2, set the relationship event, the Xib UIView dragged to the. h Area

Set a good event for touch up Inside

3, write hidden code:

-(Ibaction) Touchview: (ID) Sender { 
   [self.view endediting:yes]; 

OK, these are three kinds of more commonly used hidden keyboard methods, each can be used for different occasions and its advantages and disadvantages, see how to use.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.