监听键盘高度

首先:宏定义

//判断是否是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);

}

原文地址:https://www.cnblogs.com/leevaboo/p/3123469.html