【问题标题】:iOS8 UIKeyboardWillShowNotification Third party keyboard height [duplicate]iOS 8 KeyboardWillShowNotification第三方键盘高度[重复]
【发布时间】:2014-11-17 05:12:07
【问题描述】:

我的 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 的问题吗?还有其他方法可以动态获取键盘高度吗?

编辑:这是用户信息字典:

{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}}";
}}

提前致谢。

【问题讨论】:

    标签: ios objective-c keyboard ios8 xcode6


    【解决方案1】:

    使用

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

    获取键盘的实际大小

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 2015-06-20
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 2015-03-05
      相关资源
      最近更新 更多