美文网首页
iOS键盘遮挡输入框

iOS键盘遮挡输入框

作者: Yana0819 | 来源:发表于2018-12-03 17:08 被阅读0次

1)将输入框的代理设置为self

2)将输入框所对应的ViewController.h设置实现了UITextFieldDelegate协议

[cpp] view plaincopy

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

-(void)textFieldDidBeginEditing:(UITextField *)textField

{

CGRect frame = textField.frame;

int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);//键盘高度216

}

//当用户按下return键或者按回车键,keyboard消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

[textField resignFirstResponder];

return YES;

}

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

-(void)textFieldDidEndEditing:(UITextField *)textField

{

self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

}

[cpp] view plaincopy

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

-(void)textFieldDidBeginEditing:(UITextField *)textField

{

CGRect frame = textField.frame;

int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);//键盘高度216

}

//当用户按下return键或者按回车键,keyboard消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

[textField resignFirstResponder];

return YES;

}

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

-(void)textFieldDidEndEditing:(UITextField *)textField

{

self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

}

相关文章

网友评论

      本文标题:iOS键盘遮挡输入框

      本文链接:https://www.haomeiwen.com/subject/srxucqtx.html