ios - 获取表情符号键盘IOS 8的高度

标签 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];
        }];



    }

}

最佳答案

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

关于ios - 获取表情符号键盘IOS 8的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30059514/

相关文章:

swift - 需要帮助将 (CFPropertyListRef *)nsdictionary 转换为 swift

iOS - 检查键盘是否遮挡 View

ios - 禁用 iOS 键盘中的空格键

iOS:如何从文档目录中删除所有具有特定扩展名的现有文件?

javascript - RTCPeerConnection iOS 12.2 至 Android 7.X

ios - 为什么在 IOS 中单击按钮时 View 不显示?

objective-c - 在启用键盘返回键之前如何在 UITextField 中要求最小文本长度

iphone - 从 OSX 中删除 iOS SDK

ios - XCUITest - 如何模拟设备的锁定

iphone - 调用 UITableView 的 reloadData 方法时需要使用@synchronized 吗?