首先:宏定义
//判断是否是iphone5
#define iPhone5 ([UIScreeninstancesRespondToSelector:@selector(currentMode)] ?CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen]currentMode].size) : NO)
//监听键盘的宏定义
#define _UIKeyboardFrameEndUserInfoKey(&UIKeyboardFrameEndUserInfoKey != NULL ? UIKeyboardFrameEndUserInfoKey :@"UIKeyboardBoundsUserInfoKey")
然后,viewDiload里面写监听:
//键盘的监听事件,获取高度
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
最后在当前的controller里面写上如下方法:
//键盘事件
-(void)keyboardWillShow:(NSNotification*)notification{
CGRect _keyboardRect = [[[notification userInfo]objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue];
//如下是在此方法中去改变tabview或者其他需要调整高度的view
myTabView.frame = CGRectMake(0, 40, 320, iPhone5 ?460+88-85-_keyboardRect.size.height : 460-85-_keyboardRect.size.height);
}