2016-02-22 监听键盘 隐藏bar
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016-02-22 监听键盘 隐藏bar相关的知识,希望对你有一定的参考价值。
- (BOOL)prefersStatusBarHidden{
return YES;
} //隐藏bar
2:让键盘消失
//// [_lastField resignFirstResponder];
// [self.view endEditing:YES];//gzz0223
//
// //gzz0223 键盘消失
// NSArray *subviews = [self.view subviews];
// for (id objInput in subviews) {
// if ([objInput isKindOfClass:[UITextField class]]) {
// UITextField *theTextField = objInput;
// if ([objInput isFirstResponder]) {
// [theTextField resignFirstResponder];
// }
// }
// }
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
//监听键盘出现
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//监听键盘消失
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
//键盘出现,将chatView向上移动
- (void)keyboardWillShow:(NSNotification*)noti{
//获取键盘的高度
CGSize size = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
//屏幕宽高
CGSize winSize = self.view.frame.size;
//tableView的大小
_tableView.frame = CGRectMake(0, 0, winSize.width, winSize.height - 40 - size.height);
//chatView的位置
_chatView.frame = CGRectMake(0, winSize.height - 40 - size.height, winSize.width, 40);
}
//键盘消失,将chatView恢复原位
- (void)keyboardWillHide:(NSNotification*)noti{
//屏幕宽高
CGSize winSize = self.view.frame.size;
//tableView的大小恢复
_tableView.frame = CGRectMake(0, 0, winSize.width, winSize.height - 40);
//chatView的位置恢复
_chatView.frame = CGRectMake(0, winSize.height - 40, winSize.width, 40);
}
以上是关于2016-02-22 监听键盘 隐藏bar的主要内容,如果未能解决你的问题,请参考以下文章
EditText获取和失去焦点,软键盘的关闭,和软键盘的显示和隐藏的监听