1.遵循UItextField代理方法
UITextFieldDelegate
2.实现代理方法
//textField代理方法 实现弹出键盘时,输入框上移至不被隐藏
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(@"将要编辑");
CGFloat offset = self.view.frame.size.height - (textField.frame.origin.y + textField.frame.size.height + 216 + 150);//150 是越大 文本框向上移动的距离越大 自己可以改变数值试一下
NSLog(@"offset %f",offset);
if (offset <= 0) {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.view.frame;
frame.origin.y = offset;
self.view.frame = frame;
}];
}
return YES;
}