在開發(fā)中經(jīng)常用到監(jiān)聽鍵盤的彈出彈入宦言,并據(jù)此進(jìn)行一些操作险绘。
1.注冊監(jiān)聽
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
2.根據(jù)監(jiān)聽獲取鍵盤的高度堤舒,以此進(jìn)行后續(xù)一下操作
- (void)keyBoardWillShow:(NSNotification *)note
{
// 獲取用戶信息
NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
// 獲取鍵盤高度
CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyBoardHeight = keyBoardBounds.size.height;
// 獲取鍵盤動畫時間
CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
}
//鍵盤收起
- (void)keyBoardWillShow:(NSNotification *)note{
}