IOS keyboard Hidden

Source: Internet
Author: User

Some of the most commonly used controls in iOS development, such as textfiled and TextView, automatically eject the keyboard when clicked, but the hidden operation requires our own coding. One of the most common methods is to let textfiled and TextView give up the identity of the first responder. About the event chain of a control there's no more talking about it. We can right-click the control and associate an Edit did end exit with the Ibaction method. Add a line of code to the method. This way, when you finish typing the keyboard, clicking the return key hides the keyboard.
-(Ibaction) Textfileddidendonexit: (ID) sender {    [sender Resignfirstresponder];}

Of course one of our interfaces sometimes has a lot of keyboard response controls. We want to hide the keyboard just by clicking on the background of the control (outside the view or edit area). The most common method is: first, we first set the custom class of the view to Uicontrol (in the third inspector). Then, a way to associate the view with a touch down (only if the view's custom class belongs to Uicontrol)-( ibaction) View_touchdown: (ID) sender;. Finally, add a method to the method where the control discards the first responder's identity. [Self.textfiled Resignfirstresponder]; [Self.textview Resignfirstresponder];

-(Ibaction) View_touchdown: (ID) sender {    [self. Textfiled Resignfirstresponder];    [Self. TextView Resignfirstresponder];}

Of course, you can also use the following method without changing the custom class to Uicontrol or using custom as UIView.

-(void) touchesended: (Nsset *) touches withevent: (uievent *)event  {      if (!  [Self. TextView Isexclusivetouch]) {          [self. TextView Resignfirstresponder];      }  }

There is also a way to use the notification method. A little more trouble.



IOS keyboard Hidden

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.