//注册隐藏键盘通知
[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name: UIKeyboardWillHideNotificationobject: nil];
//隐藏键盘事件
- (void)keyboardWillHide:(id)sender{
[UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];
[UIViewsetAnimationDuration:.3f];
float width =self.view.frame.size.width;
float height =self.view.frame.size.height;
CGRect rect =CGRectMake(0,64, width, height);
self.view.frame = rect;
[UIViewcommitAnimations];
}
//页面跟随输入框焦点的确定而向上移
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];
[UIViewsetAnimationDuration:.3f];
float width =self.view.frame.size.width;
float height =self.view.frame.size.height;
if (textField.tag ==903 || textField.tag ==904 || textField.tag ==905) {
CGRect rect =CGRectMake(0, -150.0f, width, height);//216
self.view.frame = rect;
}
[UIViewcommitAnimations];
returnYES;
}
ios 解决键盘挡住输入框的问题
最新推荐文章于 2024-05-09 09:50:03 发布