iphone easy to implement keyboard hide

Source: Internet
Author: User
Tags apple apps

In Apple apps, when editing TextField and TextView, the keyboard is sometimes very annoying and does not know how to hide it. This article simply implements a toolbar with a "hide" button that allows the user to hide the keyboard at any time.

First



Code implementation

First, define a toolbar variable;

Uitoolbar *tbhide;  Toolbar for keyboard hiding

Next, create and set the toolbar;

Create keyboard toolbar, has both buttons tbhide = [[Uitoolbar alloc]initwithframe:cgrectmake (0, 0, SELF.VIEW.FRAME.S    Ize.width, 36)];    [Tbhide Setbarstyle:uibarstyleblack]; "Hide" button uibarbuttonitem * Hidebutton = [[Uibarbuttonitem alloc]initwithtitle:@ "Hide" style:uibarbuttonitemstyl    Ebordered target:self Action: @selector (Hidekeyboard)]; "Done" button uibarbuttonitem * btnspace = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemite    Mflexiblespace target:self Action:nil]; Uibarbuttonitem * Donebutton = [[Uibarbuttonitem alloc]initwithtitle:@ "Done" Style:uibarbuttonitemstyledone Target:    Self action: @selector (Hidekeyboard)];    Nsarray * Buttonsarray = [Nsarray arraywithobjects:hidebutton,btnspace,donebutton,nil];        [Tbhide Setitems:buttonsarray];    Set thoes controls that need hide keyboard functions [Self.textfield setinputaccessoryview:tbhide]; [Self.textview Setinputaccessoryview:tbhide];

Finally, the hidden keyboard function is implemented.

Hide keyboard-(void) hidekeyboard{    [[UIApplication sharedapplication] SendAction: @selector ( Resignfirstresponder) To:nil From:nil Forevent:nil];}

The above is the hidden keyboard function of the implementation part, relatively simple.

The following gives the project source code, for everyone to download!

Project Source




iphone easy to implement keyboard hide

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.