监听 UIKeyboardWillChangeFrameNotification 消息时需要注意
键盘的高度获取 在 横竖屏的情况下是不同的 正确代码如下
设置监听 :
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardFrameDidChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
//监听方法:
-(void)keyboardFrameDidChange:(NSNotification*)notice
{
NSDictionary * userInfo = notice.userInfo;
NSValue * endFrameValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect endFrame = endFrameValue.CGRectValue;
NSLog(@"%@",NSStringFromCGRect(endFrame));
//_currentKeyboardHeight 为 键盘高度
if(iOS_8()){
_currentKeyboardHeight = endFrame.size.height;
}else{
if(Is_Landscape ){
_currentKeyboardHeight = endFrame.size.width;
}else{
_currentKeyboardHeight = endFrame.size.height;
}
}
[self updateTipTableView]; // 根据 _currentKeyboardHeight 更新界面
}