// 键盘即将显示的通知
- (void)showKeyboard
{
[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
// 键盘即将消失的通知
- (void)hiddenKeyboard
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
}
// 键盘即将显示
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *kbInfo=[notification userInfo];
CGSize kbSize=[[kbInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGFloat kbHeight = kbSize.height; // 键盘高度
}j
// 键盘即将消失
- (void)keyboardWillHidden:(NSNotification *)notification
{
}
注意:键盘即将显示,或消失的通知分别添加到即将开始编辑,和即将结束编辑的代理方法中(效果可以自行验证下)。