UITextField防止键盘遮挡以及添加手势操作消失键盘
2013-11-11 15:37
471 查看
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidenKeyboard)]; gesture.numberOfTapsRequired = 1; [self.view addGestureRecognizer:gesture];
添加手势
注意添加UITextField协议
#pragma -mark UITextField delegate //UITextField的协议方法,当开始编辑时监听 -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { NSTimeInterval animationDuration=0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; float width = KDeviceWidth; float height = KDeviceHeight; //上移30个单位,按实际情况设置 CGRect rect=CGRectMake(0.0f,-50,width,height); self.view.frame=rect; [UIView commitAnimations]; return YES; } #pragma -mark View Action //恢复原始视图位置 -(void)resumeView { NSTimeInterval animationDuration=0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; float width = KDeviceWidth; float height = KDeviceHeight; float Y = 0.0f; CGRect rect=CGRectMake(0.0f,Y,width,height); self.view.frame=rect; [UIView commitAnimations]; } #pragma -mark keyboard Action //隐藏键盘 -(void)hidenKeyboard { [_userTextField resignFirstResponder]; [_passwdTextField resignFirstResponder]; [self resumeView]; } - (void)nextOnKeyboard:(UITextField *)sender { if (sender == _userTextField) { [_passwdTextField becomeFirstResponder]; }else if (sender == _passwdTextField){ [self hidenKeyboard]; [self resumeView]; } }
相关文章推荐
- UITextField防止键盘遮挡以及添加手势操作消失键盘
- 黑马程序员--UI之UIview、UITextField、NSUserDefaults以及键盘的升起与回落的基本操作
- (二)UITabBar and UINavigationController基础教程之UITextField键盘隐藏及防止键盘遮挡
- UITextField,UITextView实现键盘的自动隐藏以及遮挡时自动上移的功能
- UITableView上的UITextField防止被键盘遮挡
- 键盘操作往往需要添加一个遮盖层,防止点击其他地方导致出错
- UITextField键盘弹出遮挡的解决
- QT添加托盘以及SendInput模拟鼠标键盘用法
- TextField防止键盘遮挡
- 分享 原创的一个模拟鼠标键盘操作的 设置简单 示例可以模拟向QQ群,以及QQ群内成员发送信息。
- iOS---UITextField代理方法解决键盘遮挡文本框
- iPhone开发 当输入的键盘会挡住UITextField的处理事件,当键盘消失的时候界面还原
- [IOS]列表选择以及键盘遮挡输入框问题
- 键盘遮挡的处理。UITextField在实际的应用(综合应用, 有点小难度)
- gitolite管理员操作以及新用户添加
- UITextField滑动防止被键盘挡住 终极解决方案
- 有关UITextField被键盘遮挡的代码
- Android 对指定View(组件)添加手势操作的注意点和陷阱
- ios--解决键盘遮挡UITextField控件的问题(方式二)
- Android 在TextView,EditText中添加表情,设置输入键盘消失