Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

ios11

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 let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        print(keyboardSize)
    }
}

This is what I get when I print the size:

(0.0, 0.0, 0.0, 0.0)
(0.0, 736.0, 414.0, 0.0)

Anyone knows why this has stopped working ? Or if I have any other alternatives to get the keyboard size ?

like image 742
Adrian Avatar asked Aug 08 '17 13:08

Adrian


1 Answers

Use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey

So changing your code to the following will fix your issue:

if let userInfo = notification.userInfo {
    if let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
        print(keyboardSize)
    }
}
like image 69
Doug Amos Avatar answered Oct 06 '22 00:10

Doug Amos