//使用NSNotificationCenter 鍵盤出現時
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
//使用NSNotificationCenter 鍵盤隐藏時
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
//实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
float keyboardHeight = keyboardRect.size.height;
self.moreTableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight , 0);
}
//当键盘隐藏的时候
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
self.moreTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}