Get the height of keyboard doesn't work on IOS 11 beta

后端 未结 3 1394
故里飘歌
故里飘歌 2021-02-19 01:25

I have the following code which worked on IOS 10, but now it doesn\'t work anymore when running on IOS 11 beta.

if let userInfo = notification.userInfo {
    if          


        
3条回答
  •  有刺的猬
    2021-02-19 02:23

    I have the same issue. The answer of Doug Amos is right. I just want to make it clearer. Here is my code:

    @objc func keyboardWillShow(notification:NSNotification){
    
            var userInfo = notification.userInfo!
            var keyboardFrame:CGRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
            if keyboardFrame.size.height <= 0 { // to fix bug on iOS 11
                keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
            }
            keyboardFrame = self.view.convert(keyboardFrame, from: nil)
        }
    

提交回复
热议问题