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