how to get keyboard height for portrait and landscape in IPhone and IPad

1.9k views Asked by At

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?

2

There are 2 answers

0
Vipul On

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);
1
SGDev On

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.