iOS 键盘弹出遮挡UITextField解决方法
2017-04-05 11:30
316 查看
//增加监听,当键退出时收出消息
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//开始编辑时
视图上移
如果输入框不被键盘遮挡则不上移。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
CGFloat rects;
if(
1==textField.tag ||2==textField.tag
||3==textField.tag||4==textField.tag)
{
rects = self.view.frame.size.height
- (_topview.frame.origin.y +
40*textField.tag +
216 +50);
}
else
{
rects = self.view.frame.size.height
- (_centerView.frame.origin.y
+ 40*(textField.tag-4) +
216 +50);
}
if (rects <=
0) {
[UIView
animateWithDuration:0.3
animations:^{
CGRect frame =
self.view.frame;
frame.origin.y = rects;
self.view.frame = frame;
}];
}
return
YES;
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
[UIView
animateWithDuration:0.3
animations:^{
CGRect frame =
self.view.frame;
frame.origin.y =
64.0;
self.view.frame = frame;
}];
}
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//开始编辑时
视图上移
如果输入框不被键盘遮挡则不上移。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
CGFloat rects;
if(
1==textField.tag ||2==textField.tag
||3==textField.tag||4==textField.tag)
{
rects = self.view.frame.size.height
- (_topview.frame.origin.y +
40*textField.tag +
216 +50);
}
else
{
rects = self.view.frame.size.height
- (_centerView.frame.origin.y
+ 40*(textField.tag-4) +
216 +50);
}
if (rects <=
0) {
[UIView
animateWithDuration:0.3
animations:^{
CGRect frame =
self.view.frame;
frame.origin.y = rects;
self.view.frame = frame;
}];
}
return
YES;
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
[UIView
animateWithDuration:0.3
animations:^{
CGRect frame =
self.view.frame;
frame.origin.y =
64.0;
self.view.frame = frame;
}];
}
相关文章推荐
- iOS---UITextField代理方法解决键盘遮挡文本框
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- ionic在开发ios系统微信时键盘挡住输入框的解决方法(键盘弹出问题)
- [Cordova/Phonegap] Cordova iOS 应用在第三方输入法的键盘弹出(点击输入框)时,页面不上移,导致输入框被键盘遮挡 的解决办法
- 关于点击UIButton弹出键盘,并且键盘的上方还需添加UITextField或者UITextView的解决方法
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- ios--解决键盘遮挡UITextField控件的问题(方式一)
- ios 键盘遮挡输入框解决方法
- 键盘弹出,视图向上移,键盘高度遮住UITextField的解决方法
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- iOS 解决键盘被遮挡的方法
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- Swift 解决IOS开发中TableView中编辑UITextField时键盘遮挡输入框的情况
- 解决ios模拟器不能弹出键盘问题的方法
- iOS开发之UITextField输入长度限制,键盘遮挡自适应方法
- iOS UITextField禁止键盘弹出,同时又实现代理方法的实现方式!
- iOS项目开发键盘弹出遮挡输入框问题解决方案