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