iOS8 UIKeyboardWillShowNotification第三方键盘高度

参见英文答案 > can’t get correct value of keyboard height in iOS810个
当显示键盘时,我有一个需要调整位置的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},0}}";
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0,0}}";
}}

提前致谢.

解决方法

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

获得键盘的实际大小

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...