iPhoneX and iPhone 8 keyboard height are different

后端 未结 5 904
星月不相逢
星月不相逢 2020-12-24 11:15

I use below code to get keyboard height. Then use this height to calculate the frame of an UIView to make sure this UIView just on the top of the k

5条回答
  •  时光说笑
    2020-12-24 11:51

    This works for every device and iOS version so far

    - (void)keyboardWillShown:(NSNotification*)aNotification
    {
            NSDictionary* info = [aNotification userInfo];
            CGFloat kbHeight = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
            CGFloat safeAreaBottomInset = 0;
            if (@available(iOS 11.0, *)) {
                safeAreaBottomInset = self.view.safeAreaInsets.bottom;
            }
            self.containerViewBottomConstraint.constant += (kbHeight - safeAreaBottomInset); //In my case I use a constraint to adapt the UI when the keyboard is presented
            [self.view layoutIfNeeded];
    }
    

提交回复
热议问题