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

后端 未结 3 1419
故里飘歌
故里飘歌 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:28

    I used this code in my app with Swif 3+

        var userInfo = notification.userInfo
        if let keyboardFrame = (userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue{
            print(keyboardFrame.height)
            if keyboardFrame.size.height <= 0 { // To fix bug on iOS 11
                if let newKeyboardFrame = (userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue{
                    print(newKeyboardFrame.height)
                }
            }
        }
        view.layoutIfNeeded()
    

提交回复
热议问题