How to get the size of Keyboard when any UITextView or UITextField is enabled? (Come iOS8 and third-party keyboards, this is going to be very important)
Till iOS7, we had just one type of keyboard in iPhone/iPad. But finally with iOS8, we will be having third party keyboards which can be used throughout the device. Can't wait to install this on my iPhone.
However, many developers have been using a static size to get the size of keyboard heights, which is not a good idea! Come iOS8, this just worsens the situation. Solution?
Its right there in your code. Just that you haven't been using it yet.
You must be having a similar method for subscribing to keyboard notifications.
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
So in your listeners for these notifications, get this value :
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo]; CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; //this gives the exact size of the keyboard currently used
}
Hope this helps!
Keep coding!










