1.文本框代理
@interface ChangeCarController () <UITextFieldDelegate>
self.changeCarTxt.delegate=self;
2.文本框事件监听
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
MyLog(@"将要开始编辑");
CGFloat offset=-100;
MyLog(@"aa %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;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
MyLog(@"将要结束编辑");
[UIView animateWithDuration:0.3 animations:^{
CGRect frame=self.view.frame;
frame.origin.y=0.0;
self.view.frame=frame;
}];
return YES;
}
3.点击return隐藏键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self.changeCarTxt resignFirstResponder];
return YES;
}