Solve the problem that the keyboard blocks the input box. The keyboard blocks the input box.
1) First, follow the protocol UITextFieldDelegate @ interface userInfoViewController () <UITextFieldDelegate> 2) set the proxy (the following self is the parent view of the input box) textField. delegate = self; 3) implement the three methods of UITextFieldDelegate:-(BOOL) textFieldShouldReturn :( UITextField *) textField {
[TextField resignFirstResponder];
Return YES;
}/*** The following is a full-screen view. The view has a sub-control textField. ***/-(void) textFieldDidBeginEditing :( UITextField *) textField {CGRect frame = textField. frame; int offset = frame. origin. y + 32-(self. frame. size. height-256.0); // The keyboard height is 256, and the textField height is 32.
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations: @ "ResizeForKeyboard" context: nil];
[UIView setAnimationDuration: animationDuration];
// 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)
Self. frame = CGRectMake (0.0f,-offset, self. frame. size. width, self. frame. size. height );
[UIView commitAnimations];}-(void) textFieldDidEndEditing :( UITextField *) textField {self. frame = CGRectMake (0, 0, self. frame. size. width, self. frame. size. height);}/*** a full-screen view with tableView. Each tableViewCell has a sub-control textField. ***/-(void) textFieldDidBeginEditing :( UITextField *) textField
{
CGRect frame = textField. frame;
Int index = (int) (textField. tag-0x1000 );
// 30 is the height of textField, (index-1) is the first few cells, 90 is the y of tableView, that is, the bottom of the input box is from self. view height minus the top of the keyboard from self. view height
Int offset = frame. origin. y + (index-1) * 50 + 30 + 90-(self. view. frame. size. height-256.0); // The keyboard height is 256.
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations: @ "ResizeForKeyboard" context: nil];
[UIView setAnimationDuration: animationDuration];
// 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)
Self. infoList. frame = CGRectMake (10.0f, 90-offset, self. infoList. frame. size. width, self. infoList. frame. size. height );
[UIView commitAnimations];
}
-(Void) textFieldDidEndEditing :( UITextField *) textField
{
Self. infoList. frame = CGRectMake (10, 90, [UIScreen mainScreen]. bounds. size. width-20,300);} effect: