ios - ios8 键盘高度有所不同

标签 ios keyboard ios8

我使用下面的代码来获取键盘高度,与使用ios8的iPhone 5s设备相比,使用ios7的iPhone4s设备,键盘高度有所不同。因此,当我在使用ios8的iPhone5s中点击它时,我的文本字段移动得非常高,而相同的代码有效在 iPhone 4s 和 ios7 上都可以。有人可以指导如何在两个版本中解决该问题吗?

- (void)keyboardWasShown:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    float kbHeight;
    if (([UIApplication sharedApplication].statusBarOrientation== UIDeviceOrientationPortraitUpsideDown)||([UIApplication sharedApplication].statusBarOrientation== UIDeviceOrientationPortrait))
    {
        kbHeight=kbSize.height;
    }
    else
    {
        kbHeight=kbSize.width;
    }



    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbHeight, 0.0);

    self.scroll.contentInset = contentInsets;
    self.scroll.scrollIndicatorInsets = contentInsets;

    CGRect rect = self.view.frame;
    rect.size.height -= (kbHeight);


    if (!CGRectContainsPoint(rect, self.activeField.frame.origin))
    {
        CGPoint scrollPoint = CGPointMake(0.0, self.activeField.frame.origin.y - ((kbHeight) - self.activeField.frame.size.height));
        [self.scroll setContentOffset:scrollPoint animated:NO];
    }
}

最佳答案

只需替换代码中的行

CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

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

让我知道它是否有效

关于ios - ios8 键盘高度有所不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971819/

相关文章:

ios - 以恒定速度将 imageView 从当前位置移动到点击位置

iOS UI 与代码的连接

Objective-c : addTarget to UIButton not calling

ios - Xcode - 如何关闭模态 UIImageView?

html - 是否有 HTML 属性告诉智能手机键盘显示特殊的电子邮件键?

javascript - 调度键盘事件在 JavaScript 中不起作用

ios - MFMailComposeViewController 和 MFMessageComposeViewController 在 iOS 8 中旋转后边界有误

ios - 在registerUserNotificationSettings之后立即调用registerForRemoteNotifications?

c# - 在C#中模拟KeyPress到游戏

angularjs - iOS8 Safari 网站链接滚动后不起作用