I entered "iOS hidden keyboard" in Baidu and quickly found many articles. For example, "click return to hide", "click other places in the input box to hide", and so on.
In fact, hiding the input method is also simple. We should grasp its essence: Call the resignfirstresponder function to implement hiding (which will be described below) resignfirstresponder
Of course, you can call it anywhere below to hide the input method keyboard.
-(Void) touchesbegan :( nsset *) touches withevent :( uievent *) event
{
Nslog (@ "% @", @ "pointer began ");
}
-(Void) touchesmoved :( nsset *) touches withevent :( uievent *) event
{
Nslog (@ "% @", @ "pointer move ");
[Textfieldresignfirstresponder]; // hide the input method when sliding
}
-(Void) touchesended :( nsset *) touches withevent :( uievent *) event
{
Nslog (@ "% @", @ "pointer end ");
}
You can also click "return" to hide it automatically. Note: This method must inherit the uitextfielddelegate protocol.
Only uiviewcontroller inherits from uitextfielddelegate. The uiview class does not work if it inherits uitextfielddelegate.
We need to continue our research, so why does uiview fail.
(Ah, that's a big deal: It's because my uiview didn't implement the uitextfielddelegate protocol, plus contentfield. Delegate = self)
The resignfirstresponder submits the identity of the first responder of the Input Method to hide the content. To be continued ..... Prevent text box obstruction
This article from http://xscconan.blog.163.com/blog/static/149593132012111310351998/
The main idea is that when the keyboard pops up and is hidden, the corresponding view also has the effect of moving up or down:
Premise: View implements the protocol of the input box, contentfield. Delegate
= Self;
// When you start to edit the input box, the keyboard appears. Execute this event.
-(Void) textfielddidbeginediting :( uitextfield *) textfield
{
Int offset = 216; // frame. Origin. Y + 43-(self. Frame. Size. Height-216.0); // The keyboard height is 216.
// Move the Y coordinate of the view to the Offset Unit so that the following space is used for the display of the soft keyboard.
If (Offset>
0)
{
Nstimeinterval animationduration =
0.30f;
[Uiviewbeginanimations: @ "resizeforkeyboard" context: Nil];
[Uiviewsetanimationduration: animationduration];
Self. Frame = cgrectmake (0.0f,-offset, self. Frame. Size. Width, self. Frame. Size. Height );
[Uiviewcommitanimations];
}
}
// When the input box is hidden, the view moves down accordingly.
-(Void) textfielddidendediting :( uitextfield *) textfield
{
Nstimeinterval animationduration =
0.30f;
[Uiviewbeginanimations: @ "resizeforkeyboard" context: Nil];
[Uiviewsetanimationduration: animationduration];
// 20 is the height of topbar. The size of view. frame is [0,460].
Self. Frame = cgrectmake (0, 20,
Self. Frame. Size. Width, self. Frame. Size. Height );
[Uiviewcommitanimations];
}
Perfect implementation ..