Reputation: 89
I want to handle keyboard notifications to move textfield up and down on tap of it in portrait as well as landscape ..how to get the height of keyboard in portrait and landscape to achieve this?
Upvotes: 2
Views: 1917
Reputation: 2252
use this code
- (void)keyboardWillShow:(NSNotification*)note {
NSDictionary* info = [note userInfo];
CGSize _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
float kbHeight = _kbSize.width > _kbSize.height ? _kbSize.height : _kbSize.width;
}
it will work in all the cases. Let me know if it works.
Upvotes: 3
Reputation: 130
You can find Height of keyboard using following code.
// Works in both portrait and landscape mode
CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
kbRect = [self.view convertRect:kbRect toView:nil];
CGSize kbSize = kbRect.size;
NSLog(@"Keyboard Height: %f Width: %f", kbSize.height, kbSize.width);
Upvotes: 1