iPhone X keyboard appear showing extra space

后端 未结 6 911
别那么骄傲
别那么骄傲 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:35

    Try subtracting the height of the safe area's bottom inset when calculating the value for your constraint.

    Here is a sample implementation which handles a UIKeyboardWillChangeFrame notification.

    @objc private func keyboardWillChange(_ notification: Notification) {
        guard let userInfo = (notification as Notification).userInfo, let value = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
        let newHeight: CGFloat
        if #available(iOS 11.0, *) {
            newHeight = value.cgRectValue.height - view.safeAreaInsets.bottom
        } else {
            newHeight = value.cgRectValue.height
        }
        myConstraint.value = newHeight
    }
    

提交回复
热议问题