Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the size of the iPad on-screen keyboard after rotation
    text
    copied!<p>For an app I’m designing for the iPad, I have a scroll view with some text fields/text views in it. In order to keep everything visible, I adjust the <code>contentSize</code> property of the scroll view to add a buffer at the bottom that corresponds to how much the keyboard overlaps the scroll view. Here’s the code (there’s some app-specific stuff here, but hopefully not so much that you can’t make sense of it):</p> <pre><code>- (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:&amp;curve]; NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval duration; [animationDuration getValue:&amp;duration]; NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey]; CGRect frame; [endingFrame getValue:&amp;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:&amp;curve]; NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval duration; [animationDuration getValue:&amp;duration]; [UIView beginAnimations:@"keyboardWillHide" context:bodyView]; [UIView setAnimationCurve:curve]; [UIView setAnimationDuration:duration]; // Re-draw code here [UIView commitAnimations]; } </code></pre> <p>My question is this: what do I do about keyboard size during rotation? I don’t receive any keyboard notifications when the iPad is rotated, but the size of the keyboard changes significantly. Ideally I’d simply adjust the height of the <code>contentSize</code> property by the amount the keyboard overlaps in landscape mode, but I can't see a good way to do that without hard-coding the height of the keyboard in both orientations, which I don’t want to do.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload