iOS 11 - Keyboard Height is returning 0 in keyboard notification
Use this:
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
For Swift, you can use:
let keyboardSize = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size
swift iOS11 - identify keyboardSize height doesn't work anymore
Use UIKeyboardFrameEndUserInfoKey
instead of UIKeyboardFrameBeginUserInfoKey
Swift keyboard Height return 0
what about to check it with UIKeyboardFrameEndUserInfoKey
wouldn't this work?
UIKeyboardEventArgs FrameBegin Height returns 0 after first click
Solution:
Use FrameEnd.Height
instead of FrameBegin.Height
.
References:
UIKeyboardFrameBeginUserInfoKey
The key for an NSValue object containing a CGRect that identifies the starting frame rectangle of the keyboard in screen coordinates. The frame rectangle reflects the current orientation of the device.
UIKeyboardFrameEndUserInfoKey
The key for an NSValue object containing a CGRect that identifies the ending frame rectangle of the keyboard in screen coordinates. The frame rectangle reflects the current orientation of the device.
Apple's Documentations:
https://developer.apple.com/documentation/uikit/uikeyboardframebeginuserinfokey
https://developer.apple.com/documentation/uikit/uikeyboardframeenduserinfokey
Other related case: iOS 11 - Keyboard Height is returning 0 in keyboard notification
The height on my soft keyboard changes when triggered multiple times
The problem is that you are examining the wrong frame:
UIKeyboardFrameBeginUserInfoKey
When the keyboard is shown, what its frame height is at the beginning of the showing process is of no interest to you. What you want to know is the frame at the end of the showing process:
UIKeyboardFrameEndUserInfoKey
Also, it looks like you are getting notified of the wrong thing. You have not shown what notification you are registered for, but the name of your method, keyboardWasShown
, suggests that your are getting notified when the keyboard did show. That's too late; this notification is almost never of any interest. You want to know when the keyboard will show.
can't get correct value of keyboard height in iOS8
Use
NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
Related Topics
Send Messages Between iOS and Watchos with Watchconnectivity in Watchos2
How to Disable/Remove Firebaseanalytics
iOS 5 JSON Parsing Results in Cocoa Error 3840
Pod Install Is Staying on "Setting Up Cocoapods Master Repo"
Uitableview Dynamic Cell Heights Only Correct After Some Scrolling
Using Custom Font in a Uiwebview
Refresh Devices in Team Provisioning Profile Managed by Xcode 7
Find the Tangent of a Point on a Cubic Bezier Curve
Wrapping Text in a Uitextview Around a Uiimage Without Coretext
How to Set Device (Ui) Orientation Programmatically
How to Detect Apps First Launch in iOS
Swift 3 - Comparing Date Objects
Could Not Load the "" Image Referenced from a Nib in the Bundle with Identifier
Copy Nsattributedstring in Uipasteboard
Wkwebview Content Loaded Function Never Get Called