文本框遮盖解决方案

#pragma mark ------ UITextFieldDelegate

 

#if 0

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField resignFirstResponder];

    return YES;

}

//开始编辑输入框的时候,软键盘出现,执行此事件

-(void)textFieldDidBeginEditing:(UITextField *)textField

{

    CGRect frame = textField.frame;

    int offset = frame.origin.y  - (kAllHeight - 216.0);//iPhone键盘高度216iPad的为352

    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

    [UIView setAnimationDuration:0.3f];

    //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

    if(offset > 0)

        self.view.frame = CGRectMake(0.0f, -offset, kScreenWidth, kBodyHeight);

    [UIView commitAnimations];

}

//输入框编辑完成以后,将视图恢复到原始状态

-(void)textFieldDidEndEditing:(UITextField *)textField

{

    [UIView beginAnimations:@"ResizeForKeyboardDown" context:nil];

    [UIView setAnimationDuration:0.3f];

    self.view.frame =CGRectMake(0, 44 + 20, kScreenWidth, kBodyHeight);

    [UIView commitAnimations];

}

 

原文地址:https://www.cnblogs.com/zero-zql/p/4968421.html