iPhoneX and iPhone 8 keyboard height are different

后端 未结 5 1022
星月不相逢
星月不相逢 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:29

    override func viewDidLoad() { super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
    }
    //Here keyboard is without any toolbar and suggestions boxes
    @objc func keyboardWillShow(notification: NSNotification) {
        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            let keyboardHeight = ((keyboardSize.height) > 240) ? 220 :  (keyboardSize.height - 47)
            self.view.layoutIfNeeded()
        }
    
    }
    

提交回复
热议问题