弹出键盘,输入框上移问题 iOS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了弹出键盘,输入框上移问题 iOS相关的知识,希望对你有一定的参考价值。
viewDidLoad 中添加监听
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHidden:) name:UIKeyboardWillHideNotification object:nil];
实现两个监听方法
- (void)keyboardShow:(NSNotification *)notification{
if(currentTextField.tag >= 1000){
CGSize size = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;//键盘大小
CGFloat keyBoardHeight = size.height+10;//键盘高度,富余10点高度
// screenHeight 手机屏幕总高度, 64是导航栏的高度, currentTextField.bottomY 当前textField的底部位置,
CGFloat shouldMoveHeight = keyBoardHeight-( screenHeight - 64-currentTextField.bottomY);
if(shouldMoveHeight > 0){
_bgScrollView.contentOffset = CGPointMake(0, shouldMoveHeight);
}
}
}
- (void)keyboardHidden:(NSNotification *)notification{
_bgScrollView.contentOffset = CGPointMake(0, 0);
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
以上是关于弹出键盘,输入框上移问题 iOS的主要内容,如果未能解决你的问题,请参考以下文章