title: Why can't I get the height between the nav bar and the top of the keyboard correctly?
body: <p>I have a weird problem.  I'm trying to calculate the exact height between the bottom of the navigation bar and the top of the keyboard no matter which iOS device I'm running the app on.  Here is the method where I'm doing this calculation:</p>
  <pre><code>    @objc func keyboardWillShow(_ notification: Notification) {
          if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
              let keyboardRectangle = keyboardFrame.cgRectValue
              let keyboardHeight = keyboardRectangle.height
              let navigationBarHeight: CGFloat = self.navigationController!.navigationBar.frame.height
              let viewableArea = screenSize.height - keyboardRectangle.height - reportPostInstructionContainerViewHeight - characterCountContainerViewHeight - reportPostInstructionContainerViewHeight + 4
              //iPhone 12 and above is &quot;- 20&quot;; iPhone 8 needs to be &quot;+ 4&quot;; iPhone 12 mini is &quot;- 24&quot;
                          
              print(&quot;**** navigationBarHeight: \(navigationBarHeight)&quot;)
              print(&quot;**** keyboardHeight: \(keyboardHeight)&quot;)
              print(&quot;**** screenSize.height: \(screenSize.height)&quot;)
              print(&quot;**** total screen height - keyboard height: \(screenSize.height - keyboardRectangle.height)&quot;)
              print(&quot;**** viewableArea: \(viewableArea)&quot;)
              textViewHeight = viewableArea
              print(&quot;**** textViewHeight: \(textViewHeight)&quot;)
              
              UIView.animate(withDuration: 0.01, animations: { () -&gt; Void in
                  self.textView.anchor(
                      top: self.horizontalDividerView.bottomAnchor,
                      leading: self.view.leadingAnchor,
                      bottom: nil,
                      trailing: self.view.trailingAnchor,
                      identifier: &quot;ReportPostPFAVC.textView.directionalAnchors&quot;,
                      size: .init(width: 0, height: self.textViewHeight)
                  )
                  self.textView.layoutIfNeeded()
              })
          }
      }
  
  </code></pre>
  <p>The line where &quot;viewableArea&quot; is being calculated seems to be the issue.  For example, if I'm running the app on an iPhone 8, I need to add 4 to this calculation in order to size the text view properly.</p>
  <p>Here is an image for reference:</p>
  <p><a href="https://i.stack.imgur.com/0rSkX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0rSkX.png" alt="Screenshot showing that the bar with the &quot;Report&quot; button is correctly sitting on top of the keyboard" /></a></p>
  <p>I'm trying to get the bar with the &quot;Report&quot; button to sit perfectly on top of the keyboard.  But, if I test on different devices sometimes I need to subtract 20 or 24 instead of adding 4.</p>
  <p>I don't really understand where this gap is coming from.</p>
  <p>Can anyone advise?</p>