title: iOS keyboard height returned incorrectly on UIKeyboardWillShowNotification/
body: <p>I am trying to scroll my text view up when keyboard is presented. I am trying to follow Apple's own tutorial at <a href="https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html" rel="noreferrer">https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html</a>. Instead of scroll views and frames I am using autolayout, but the general idea is same (subscribing to keyboard notifications, and animating the layout constraints accordingly). However, when I display the keyboard, there is a gap between the text view and the keyboard: (this is a screenshot from Turkish keyboard, but the same gap, marked with red, is present in all keyboards installed, including custom ones). (Screenshot from iPhone 6 Plus, but the issue is also present on other screen sizes too)</p>
  
  <p><img src="https://i.stack.imgur.com/DlmMM.png" alt="enter image description here"></p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/25874975/cant-get-correct-value-of-keyboard-height-in-ios8">can&#39;t get correct value of keyboard height in iOS8</a> and I've tried using both <code>UIKeyboardFrameEndUserInfoKey</code> and <code>UIKeyboardFrameBeginUserInfoKey</code> but they all result in the same gap. I've tried attaching <code>UIKeyboardWillShowNotification</code> and on <code>UIKeyboardDidShowNotification</code> but still, I'm getting the same gap. I think the gap is related to suggestions on some keyboards on iOS 8, but it shouldn't report the keyboard size with suggestions when suggestions is not present.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>- (void)viewDidLoad {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
      [self registerForKeyboardNotifications];
  }
  
  - (void)registerForKeyboardNotifications
  {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWillBeShown:)
                                                   name:UIKeyboardWillShowNotification object:nil];
  
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWillBeHidden:)
                                                   name:UIKeyboardWillHideNotification object:nil];
  
  }
  
  // Called when the UIKeyboardDidShowNotification is sent.
  - (void)keyboardWillBeShown:(NSNotification*)aNotification
  {
      NSDictionary* info = [aNotification userInfo];
      CGRect kb = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  
      float height = kb.size.height;
      sendZoneBottomConstraint.constant = height;
      [UIView animateWithDuration:.2 animations:^{
          [self.view layoutIfNeeded];
      }];
  }
  
  // Called when the UIKeyboardWillHideNotification is sent
  - (void)keyboardWillBeHidden:(NSNotification*)aNotification
  {
      sendZoneBottomConstraint.constant = 0;
      [UIView animateWithDuration:.2 animations:^{
          [self.view layoutIfNeeded];
      }];
  }
  </code></pre>
  
  <p><code>sendZoneBottomConstraint</code> is that bottom-most view's bottom spacing to the bottom layout guide. </p>
  
  <p><strong>UPDATE:</strong> I've tried changing the keyboard rectangle from window coordinates to my view's coordinates but it didn't change anything. Here is what I tried:</p>
  
  <pre><code>CGRect kb = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  kb = [self.view.window convertRect:kb toView:self.view];
  float height = kb.size.height;
  </code></pre>
  
  <p><strong>UPDATE, VOL 2:</strong> I've also seen <a href="https://stackoverflow.com/questions/26268743/ios-8-orientation-change-keyboard-frame-does-not-display-correctly/26491266#26491266">iOS 8 Orientation change: Keyboard frame does not display correctly</a> but I'm experiencing the issue also on iPhone 5s iOS 7.1 Simulator, so it's not an iOS 8-only issue.
  How can I solve this problem? I definitely don't want to hard code any keyboard height values in iOS 8 world.</p>
  
  <p><strong>UPDATE, VOL 3:</strong> I've also tried it with English keyboard with suggestions both on and off. It still appears with respect to the total size of the keyboard, so it's not about the suggestions/autocomplete view:</p>
  
  <p><img src="https://i.stack.imgur.com/VB83s.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/7aKkG.png" alt="enter image description here"></p>