title: Resize a view when a keyboard appears (iOS)
body: <p>I realize there are many similar solutions, such as <a href="https://github.com/michaeltyson/TPKeyboardAvoiding" rel="nofollow noreferrer">TPKeyboardAvoiding</a>, <a href="https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html" rel="nofollow noreferrer">Apple's famous solution</a>, and various suggestions involving the use of UIScrollView. In my case, I need to resize a view to accommodate the keyboard rather than scroll or move it. <a href="https://stackoverflow.com/questions/8704137/keeping-object-on-top-of-keyboard-in-the-event-of-becomefirstresponder-or-resign/8704371#8704371">This solution</a> comes closest to what I'm trying to achieve, so it was my basis. However I'm having an issue making things work in landscape mode. My method that resizes the view when the keyboard appears is this:</p>
  
  <pre><code>- (void)keyboardWillShow:(NSNotification *)note {
      NSDictionary *userInfo = note.userInfo;
      NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
      UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
  
      CGRect keyboardFrame = [[self textField].superview convertRect:[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil];
      CGRect statusBarFrame = [[self textField].superview convertRect:[UIApplication sharedApplication].statusBarFrame fromView:nil];
  
      CGRect bounds = [self textField].superview.bounds;    
      CGRect newFrame = CGRectMake(0.0, 0.0, bounds.size.width, keyboardFrame.origin.y + statusBarFrame.size.height);
      [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState | curve animations:^{
          [self textField].superview.frame = newFrame;
      } completion:nil];
  }
  </code></pre>
  
  <p>This works perfectly in portrait mode.</p>
  
  <p><img src="https://i.stack.imgur.com/o7Pdw.png" alt="enter image description here"></p>
  
  <p>However, in landscape mode, the view resizes from left-to-right or right-to-left depending upon in which direction the device was rotated, rather than from the bottom up.</p>
  
  <p><img src="https://i.stack.imgur.com/R6sU8.png" alt="enter image description here"></p>
  
  <p>Clearly there is something wrong with how I'm using coordinates, and some frame of reference isn't what I think it is when in landscape mode, but I'm having a heck of a time sorting out how to resolve it. I've tried converting all kinds of things with -convertRect: but nothing I'm trying is getting me anywhere.</p>
  
  <p>I'm really hoping someone who's less confused by all these rectangles and how they change when orientation changes can spot what I'm doing wrong and what I need to do to get this right. For reference, I've <a href="https://github.com/bkocik/KeyboardResize" rel="nofollow noreferrer">created a project</a> showing the simplest case that reproduces the problem I'm having.</p>