弹出键盘 挡住输入框的问题
挡在弹出键盘的时候,键盘挡住了输入框,有几种办法可以解决(输入框在tableview上)
1、可以考虑当键盘在弹出的时候改变tableview的高度
2、可以在键盘弹出的时候发送通知改变tableview的ContentInset
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
监听键盘是否出现
#pragma mark 键盘出现
-(void)keyboardWillShow:(NSNotification *)note
{
CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
self.tableview.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
}
#pragma mark 键盘消失
-(void)keyboardWillHide:(NSNotification *)note
{
self.tableview.contentInset = UIEdgeInsetsZero;
}
具体实现方法。
如果输入框不是在tableview上那也可以在键盘弹出的时候改变输入框的位子,键盘消失的时候复原
转载于:https://www.cnblogs.com/Toney-c/p/5848492.html