监听键盘高度

首先:宏定义

//判断是否是iphone5

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(6401136), [[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 userInfoobjectForKey:_UIKeyboardFrameEndUserInfoKey]CGRectValue];

//如下是在此方法中去改变tabview或者其他需要调整高度的view

    myTabView.frame = CGRectMake(040320iPhone5 ? 460+88-85-_keyboardRect.size.height :460-85-_keyboardRect.size.height);

}

posted @ 2013-06-07 11:09  leevaboo  Views(141)  Comments(0Edit  收藏  举报