iOS解决键盘遮挡输入框的问题

来源:互联网 发布:stc89c52单片机原理图 编辑:程序博客网 时间:2024/06/02 23:24
-(void)textFieldDidBeginEditing:(UITextField *)textField{  CGRect frame = textField.frame;  int offset = frame.origin.y + 100 - (UISCREEN_HEIGHT - 480.0);//键盘高度  NSTimeInterval animationDuration = 0.30f;  [UIView beginAnimations:@"ResizeForKeyboard" context:nil];  [UIView setAnimationDuration:animationDuration];    //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示  if(offset > 0)    self.view.frame = CGRectMake(0.0f, -offset, UISCREEN_WIDTH, UISCREEN_HEIGHT);  [UIView commitAnimations];}-(BOOL)textFieldShouldReturn:(UITextField *)textField {//按“完成”隐藏键盘  [textField resignFirstResponder];//隐藏输入键盘  return YES;}//输入框编辑完成以后,将视图恢复到原始状态-(void)textFieldDidEndEditing:(UITextField *)textField{  self.view.frame = CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT);}

0 0