标签:
- (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);
}
标签:
原文地址:http://www.cnblogs.com/gzz2016/p/5208892.html