解决键盘遮挡输入框(UITextField)问题
2013-02-28 17:03
471 查看
1.实现UITextFiledDelegate中的协议方法
2.恢复移动的视图的方法
3.点击背景隐藏键盘及响应键盘上Return按键的方法
//UITextField的协议方法,当开始编辑时监听 -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 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; //上移30个单位,按实际情况设置 CGRect rect=CGRectMake(0.0f,-30,width,height); self.view.frame=rect; [UIView commitAnimations]; return YES; }
2.恢复移动的视图的方法
//恢复原始视图位置 -(void)resumeView { 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; //如果当前View是父视图,则Y为20个像素高度,如果当前View为其他View的子视图,则动态调节Y的高度 float Y = 20.0f; CGRect rect=CGRectMake(0.0f,Y,width,height); self.view.frame=rect; [UIView commitAnimations]; }
3.点击背景隐藏键盘及响应键盘上Return按键的方法
//隐藏键盘的方法 -(void)hidenKeyboard { [self.userNameText resignFirstResponder]; [self.passwordText resignFirstResponder]; [self resumeView]; } //点击键盘上的Return按钮响应的方法 -(IBAction)nextOnKeyboard:(UITextField *)sender { if (sender == self.userNameText) { [self.passwordText becomeFirstResponder]; }else if (sender == self.passwordText){ [self hidenKeyboard]; } }
相关文章推荐
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- 解决键盘遮挡输入框(UITextField)问题
- 解决键盘遮挡输入框(UITextField)问题
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法
- 解决键盘遮挡输入框问题
- ios--解决键盘遮挡UITextField控件的问题(方式二)
- UITextField被键盘遮挡问题解决方法
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法 2012-10-31 15:10 1743人阅读 评论(0) 收藏 举报 两步: 1重载textFieldDidBe
- 弹出键盘时遮挡输入框的问题解决
- 解决iOS键盘弹出遮挡输入框问题
- iOS解决键盘遮挡输入框问题
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法
- Android WebView 软键盘遮挡输入框问题的解决方法
- ios--解决键盘遮挡UITextField控件的问题(方式一)
- iOS解决键盘遮挡输入框的问题
- 如何解决键盘遮挡输入框问题
- Android WebView 全屏下 输入框被键盘遮挡 问题解决
- 一招解决全局键盘遮挡输入框问题
- 一句代码就能轻松解决键盘遮挡住输入框的问题