首页 > 学院 > 开发设计 > 正文

防止键盘挡住textFiled的解决方案

2019-11-09 16:45:22
字体:
来源:转载
供稿:网友
键盘出现实现textfield的代理方法- (void)textFieldDidBeginEditing:(UITextField *)textField{   CGRect frame = textField.frame;   CGPoint rootFrame = [[textField superview] convertPoint:frame.origin toView:self.view];//把控件的坐标转为相对于屏幕的坐标   int offset = rootFrame.y + 56 - (self.view.frame.size.height - 216.0);//键盘高度216   NSTimeInterval animationDuration = 0.30f;   [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];   [UIView setAnimationDuration:animationDuration];   float width = self.view.frame.size.width;   float height = self.view.frame.size.height;   if(offset > 0){       CGRect rect = CGRectMake(0.0f, -offset,width,height);       self.view.frame = rect;   }   [UIView commitAnimations];}键盘收起- (IBAction)hideKeyboard:(id)sender {   NSTimeInterval animationDuration = 0.30f;   [UIView beginAnimations:@"ResizeForKeyboard" context:nil];   [UIView setAnimationDuration:animationDuration];   CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);   self.view.frame = rect;   [UIView commitAnimations];   //在这把textField的第一焦点去掉}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表