//注册键盘出现的通知
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
//注册键盘消失的通知
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
//键盘出来时的操作
- (void)keyboardWasShown:(NSNotification*)aNotification
{
//键盘高度
CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
}
//键盘消失时的操作
-(void)keyboardWillBeHidden:(NSNotification*)aNotification
{
}
记得最后要删除监听
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
网友评论