iOS 键盘遮挡输入框解决方案
2016-12-21 14:30
549 查看
//
方法一
- (void)addNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)info {
CGRect keyboardBounds = [[[infouserInfo]
objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
float f = keyboardBounds.size.height;
self.view.frame =CGRectMake(0,0,f,
0);
}
- (void)keyboardWillHide:(NSNotification *)info {
self.view.frame =CGRectMake(self.view.frame.size.height,0,
0,0);
}
//
方法二
//
开始编辑输入弹出键盘
- (void)textFieldDidBeginEditing:(UITextField *)textField {
CGRect frame = textField.frame;
int offset = frame.origin.y
+ 32 - (self.view.frame.size.height
- 216.0);//键盘高度216
NSTimeInterval animationDuration =
0.30f;
[UIView
beginAnimations:@"ResizeForKeyboard"
context:nil];
[UIView
setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset >
0)
self.view.frame =
CGRectMake(0.0f, -offset,
self.view.frame.size.width,
self.view.frame.size.height);
[UIView
commitAnimations];
}
//
当用户按下return键收回键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField
resignFirstResponder];
return YES;
}
//
输入框编辑完成后,将视图恢复到原始状态
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.view.frame =CGRectMake(0,
0, self.view.frame.size.width,
self.view.frame.size.height);
}
方法一
- (void)addNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)info {
CGRect keyboardBounds = [[[infouserInfo]
objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
float f = keyboardBounds.size.height;
self.view.frame =CGRectMake(0,0,f,
0);
}
- (void)keyboardWillHide:(NSNotification *)info {
self.view.frame =CGRectMake(self.view.frame.size.height,0,
0,0);
}
//
方法二
//
开始编辑输入弹出键盘
- (void)textFieldDidBeginEditing:(UITextField *)textField {
CGRect frame = textField.frame;
int offset = frame.origin.y
+ 32 - (self.view.frame.size.height
- 216.0);//键盘高度216
NSTimeInterval animationDuration =
0.30f;
[UIView
beginAnimations:@"ResizeForKeyboard"
context:nil];
[UIView
setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset >
0)
self.view.frame =
CGRectMake(0.0f, -offset,
self.view.frame.size.width,
self.view.frame.size.height);
[UIView
commitAnimations];
}
//
当用户按下return键收回键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField
resignFirstResponder];
return YES;
}
//
输入框编辑完成后,将视图恢复到原始状态
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.view.frame =CGRectMake(0,
0, self.view.frame.size.width,
self.view.frame.size.height);
}
相关文章推荐
- iOS 键盘遮挡输入框的解决方案
- IOS 键盘遮挡输入框 视图上移解决方案
- 在ios中避免键盘遮挡了输入框的处理
- 关于ios键盘遮挡输入框
- iOS键盘遮挡文本框的解决方案
- [IOS]列表选择以及键盘遮挡输入框问题
- ios开发时,键盘遮挡输入框解决方法
- iOS键盘遮挡输入框,输入区域自动上移
- iOS输入框怎样避免键盘的遮挡
- iOS讲解迷惑之键盘弹出遮挡输入框的问题
- 关于ios键盘遮挡输入框
- iOS 隐藏键盘,输入法,防止遮挡输入框
- 关于ios键盘遮挡输入框
- iOS输入框自适应键盘高度,避免遮挡
- iOS键盘弹出遮挡输入框问题
- ios键盘弹起不遮挡输入框
- Flex 开发android程序键盘遮挡输入框解决方案
- iOS键盘遮挡解决方案
- IOS开发Swift语言键盘遮挡输入框(UITextField)
- ios键盘不遮挡输入框