iOS8 KeyboardWillShowNotification 第三方键盘高度

标签 ios objective-c keyboard ios8 xcode6

<分区>

我的 UI 在显示键盘时需要进行一些位置调整。

以下用于检测何时显示键盘:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

注意:我已经尝试过 UIKeyboardWillShowNotification 和 UIKeyboardDidShowNotification

- (void)keyboardWillShow:(NSNotification *)n {
    if (isKeyboardShowing)
    return;

NSDictionary* userInfo = [n userInfo];

// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;


// Animate keyboard shift
[self.view layoutIfNeeded];

[UIView animateWithDuration:0.2f animations:^{
    // some animation here
} completion:^(BOOL finished) {
    if (finished)
        isKeyboardShowing = YES;
}];

对于自定义键盘,键盘大小返回 {320, 0}。由于键盘现在可以有不同的高度,因此我无法在出现键盘时使用静态值来更改 UI。

这是 ios8 的问题吗?还有其他动态获取键盘高度的方法吗?

编辑:这是 userInfo Dict:

{name = UIKeyboardDidShowNotification; userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 7;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
}}

提前致谢。

最佳答案

使用

CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

获取键盘的实际大小

关于iOS8 KeyboardWillShowNotification 第三方键盘高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25987592/

相关文章:

ios - 使用 Objective-C 在 iOS 的 NSMutableDictionary 中添加值

iPhone 键盘没有显示

jquery-ui - jqueryui 可以用键盘排序吗?

ios - 关于IOS内存管理的困惑

ios - 链接 Storyboard引用时出现 ibtool 错误 : The file "Info.plist" couldn't be saved in the folder *. storyboardc

ios - 获取 UIScrollView 的屏幕截图,包括屏幕外的部分

objective-c - Objective-c 中的不变性

ios - UITableView 单元格内容未正确显示

react-native - 警告 : Functions are not valid as a React child.( react 原生)

iphone - 为什么这个 while 循环导致 100% cpu