Getting iPad Screen Keyboard Size After Rotation

For the Im app designed for iPad, I have a scroll view with some text fields / text views in it. To make everything visible, I adjust the scroll contentSize property to add a buffer at the bottom that matches how much the keyboard overlaps the scroll view. Here is the code (there are some applications for a specific application here, but hopefully not so much that you cannot understand this):

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self name:nil object:nil]; } - (void)keyboardWillShow:(NSNotification *)aNotification { NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey]; UIViewAnimationCurve curve; [animationCurve getValue:&curve]; NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval duration; [animationDuration getValue:&duration]; NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey]; CGRect frame; [endingFrame getValue:&frame]; [UIView beginAnimations:@"keyboardWillShow" context:bodyView]; [UIView setAnimationCurve:curve]; [UIView setAnimationDuration:duration]; // Re-draw code here. [UIView commitAnimations]; } - (void)keyboardWillHide:(NSNotification *)aNotification { NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey]; UIViewAnimationCurve curve; [animationCurve getValue:&curve]; NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval duration; [animationDuration getValue:&duration]; [UIView beginAnimations:@"keyboardWillHide" context:bodyView]; [UIView setAnimationCurve:curve]; [UIView setAnimationDuration:duration]; // Re-draw code here [UIView commitAnimations]; } 

My question is: what should I do with the keyboard size during rotation? I do not receive any keyboard notifications when the iPad rotates, but the size of the keyboard changes significantly. Ideally, Id just adjusts the height of the contentSize property to the amount of keyboard overlap in landscape mode, but I don’t see a good way to do this without hard-coding the keyboard height in both orientations, which I don’t know how to do.

+7
ios uikeyboard ipad
source share
1 answer

I accidentally found out the answer to this debugging is something else. It turns out that when the iPad rotates from portrait to landscape, the portait keyboard hides (and sends its notification) just before the on-screen keyboard appears (and sends its notification). Therefore, while you are explaining this, you are all right.

+16
source share

All Articles