Implement the following four methods: If the pop-up keyboard will cover the input box and the overall interface will move up, it will not cover the input box. Add the uitextfielddelegate delegate by yourself.
Only applicable to iPhone. If you want to support iPad, you only need to change 216 to the keyboard height on the iPad.
-(Void) keyboardwillshow :( nsnotification *) noti
{
// Adjust the keyboard input interface
// Keyboard height
Float heights = 216.0;
Cgrect frame = self. View. frame;
Frame. size = cgsizemake (frame. Size. Width, frame. Size. Height-height );
[Uiview beginanimations: @ "curl" context: Nil]; // starts the animation.
[Uiview setanimationduration: 0.30];
[Uiview setanimationdelegate: Self];
[Self. View setframe: frame];
[Uiview commitanimations];
}
-(Bool) textfieldshouldreturn :( uitextfield *) textfield
{
// When the user presses return, take focus away from the text field so that the keyboard is dismissed.
Nstimeinterval animationduration = 0.30f;
[Uiview beginanimations: @ "resizeforkeyboard" context: Nil];
[Uiview setanimationduration: animationduration];
Cgrect rect = cgrectmake (0.0f, 0.0f, self. View. Frame. Size. Width, self. View. Frame. Size. Height );
Self. View. Frame = rect;
[Uiview commitanimations];
[Textfield resignfirstresponder];
Return yes;
}
-(Void) textfielddidbeginediting :( uitextfield *) textfield
{
Cgrect frame = textfield. frame;
Int offset = frame. Origin. Y + 32-(self. View. Frame. Size. Height-216.0); // The keyboard height is 216.
Nstimeinterval animationduration = 0.30f;
[Uiview beginanimations: @ "resizeforkeyboard" context: Nil];
[Uiview setanimationduration: animationduration];
Float width = self. View. Frame. Size. width;
Float Height = self. View. Frame. Size. height;
If (Offset> 0)
{
Cgrect rect = cgrectmake (0.0f,-offset, width, height );
Self. View. Frame = rect;
}
[Uiview commitanimations];
}
-(Ibaction) backgroundtap :( ID) sender {
[Remarksfield resignfirstresponder];
[Self textfieldshouldreturn: remarksfield];
}