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?
Asked
Active
Viewed 1,895 times
2
-
r u try in ios7 or ios8 – Anbu.Karthik Nov 18 '14 at 07:33
-
gd question my friend, – Anbu.Karthik Nov 18 '14 at 07:41
-
I want it to work in both ios7 and ios8 – puneetha koopadira Nov 18 '14 at 08:48
2 Answers
3
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.

SGDev
- 2,256
- 2
- 13
- 29
1
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);

Anbu.Karthik
- 82,064
- 23
- 174
- 143

Vipul
- 130
- 8