iPhone X keyboard appear showing extra space

后端 未结 6 918
别那么骄傲
别那么骄傲 2020-12-14 07:54

I have created a chat UI in which I have added a constraint for the tableView to the bottom of the screen. I am changing the constraint value by ad

6条回答
  •  温柔的废话
    2020-12-14 08:51

    The keyboard value reported by UIKeyboardFrameBeginUserInfoKey is different in these two cases in iPhone X:

    • Keyboard was not visible, a text field becomes first responder
    • Keyboard was already visible, a different text field becomes first responder.

    To get the final height of the keyboard of the keyboard (including the safe area insets) use UIKeyboardFrameEndUserInfoKey.

    In iOS 11 (iPhone X particularly), you may consider subtracting the safe area bottom insets.

        NSValue *keyboardEndFrameValue = notification.userInfo[UIKeyboardFrameEndUserInfoKey];
        if (keyboardEndFrameValue != nil) {
            CGRect keyboardSize = [keyboardEndFrameValue CGRectValue];
            _keyboardHeight = keyboardSize.size.height;
            if (@available(iOS 11.0, *)) {
                CGFloat bottomSafeAreaInset = self.view.safeAreaInsets.bottom;
                _keyboardHeight -= bottomSafeAreaInset;
            } else {
                // Fallback on earlier versions
            }
        }
    

提交回复
热议问题