//監(jiān)聽當(dāng)鍵盤將要出現(xiàn)時(shí)
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];
//監(jiān)聽當(dāng)鍵將要退出時(shí)
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotificationobject:nil];
//當(dāng)鍵盤出現(xiàn)
- (void)keyboardWillShow:(NSNotification *)notification{
//獲取鍵盤的高度NSDictionary *userInfo = [notification userInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [value CGRectValue];int height = keyboardRect.size.height;
}
//當(dāng)鍵退出
- (void)keyboardWillHide:(NSNotification *)notification{
//獲取鍵盤的高度NSDictionary *userInfo = [notification userInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [value CGRectValue];
int height = keyboardRect.size.height;
}
轉(zhuǎn)載:http://www.cocoachina.com/bbs/read.php?tid-329755.html