- (void)onKeyboardNotification:(NSNotification *)notification {
CGRect keyboardFrame = ((NSValue *) notification.userInfo[UIKeyboardFrameEndUserInfoKey]).CGRectValue;git
...
}app
-------------------分割線-------------------ide
- (void)viewWillAppear:(BOOL)animated{
//設置狀態欄白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
[self.textField becomeFirstResponder];
self.textField.text = @"" ;
//註冊鍵盤將要彈出的提醒
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
//註冊鍵盤將要消失時的提醒
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
//移除一切編輯狀態
[self.view endEditing:YES];
//移除註冊的鍵盤將要顯示的通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
// //移除註冊的鍵盤將要隱藏的通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
_tableView.frame = CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64);
}動畫
- (void)keyboardShow:(NSNotification *)notification {
NSDictionary * info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
NSLog(@"%f__________", kbSize.height);
_tableView.frame = CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64 - kbSize.height);spa
//也可使用UIView動畫.net
}
- (void)keyboardHide:(NSNotification *)notification {
// NSDictionary * info = [notification userInfo];
// CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// NSLog(@"%f__________", kbSize.height);
_tableView.frame = CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64);
}server