获取iOS设备键盘高度

来源:互联网 发布:fastdfs nginx 404 编辑:程序博客网 时间:2024/06/06 03:11
    //增加监听,当键盘出现或改变时收出消息    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];    //增加监听,当键退出时收出消息    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification   object:nil];- (void)keyboardWillShow:(NSNotification *)aNotification{    NSDictionary *userInfo = [aNotification userInfo];    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];    CGRect keyboardRect = [aValue CGRectValue];    int height = keyboardRect.size.height;    int width = keyboardRect.size.width;    NSLog(@"键盘高度是  %d",height);    NSLog(@"键盘宽度是  %d",width);    self.keyboardRect = keyboardRect;}//当键退出时调用- (void)keyboardWillHide:(NSNotification *)aNotification{}

0 0