获得表情符号键盘IOS 8的高度

时间:2015-05-05 17:27:59

标签: ios objective-c uikeyboard

键盘信息字典返回表情符号键盘高度的错误数字。如果我单击文本字段,它可以正常激活普通键盘,但是当我点击表情符号时,它仍然认为高度是标准键盘。为什么?有没有办法以编程方式获得备用(表情符号)键盘高度。常数37是一个可怕的黑客,我投入使其工作。

- (void)keyboardWillShow:(NSNotification *)notification {
    if (!IS_SHOWING_KEYBOARD)   {
        IS_SHOWING_KEYBOARD=YES;

        NSDictionary *userInfo = [notification userInfo];
        CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
        keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

        [self.view layoutIfNeeded];
        self.commentTopLayout.constant -= keyboardSize.height;
        self.commentBottomLayout.constant -= keyboardSize.height;
        [UIView animateWithDuration:0.2f animations:^{
            [self.view layoutIfNeeded];
        }];

    } else { //move him down, then up again. //clicked on emojis
        NSDictionary *userInfo = [notification userInfo];
        CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
        keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

        [self.view layoutIfNeeded];
        self.commentTopLayout.constant += keyboardSize.height;
        self.commentBottomLayout.constant += keyboardSize.height;
        [UIView animateWithDuration:0.2f animations:^{
            [self.view layoutIfNeeded];
        }];



        [self.view layoutIfNeeded];
        self.commentTopLayout.constant -= keyboardSize.height+37;
        self.commentBottomLayout.constant -= keyboardSize.height+37;

        [UIView animateWithDuration:0.2f animations:^{
            [self.view layoutIfNeeded];
        }];



    }

}

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。只需将UIKeyboardFrameBeginUserInfoKey替换为UIKeyboardFrameEndUserInfoKey即可。 : - )