title: How to get the screen height after orientation change?
body: <p>I'm getting some strange results when querying <code>UIScreen.main.bounds.height</code> after an orientation change. Maybe this isn't the correct way to do it.</p>
  
  <p>I have an observer that listens for the <code>NSNotification.Name.UIDeviceOrientationDidChange</code> event:</p>
  
  <pre><code>NotificationCenter.default.addObserver(self, selector: #selector(self.orientationChange), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
  </code></pre>
  
  <p>This calls a function that sets a constraint to 75% of the new screen height. This works fine on iPhone but iPad returns the wrong screen height. </p>
  
  <p>If the iPad is in <strong>landscape</strong> orientation <code>UIScreen.main.bounds.height</code> will return a value equal to the height in <strong>portrait</strong> orientation and vice versa.</p>
  
  <pre><code>func orientationChange() {
      // This will print the correct value on iPhone and iPad.
      if UIDevice.current.orientation.isLandscape {
          print("Landscape")
      } else {
          print("Portrait")
      }
  
      let screenSize = UIScreen.main.bounds
      let screenHeight = screenSize.height
      self.searchViewHeightConstraint.constant = screenHeight * 0.75
  
      // Correct value on iPhone. Incorrect on iPad.
      print("screenHeight: '\(screenHeight)'") 
  
      UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseOut, animations: {
          self.searchView.superview?.layoutIfNeeded()
      }, completion: nil)
  }
  </code></pre>
  
  <p>I've also come across the <code>viewWilltransition</code> method of monitoring orientation change but this behaves in the exact opposite way to the method above. ie. the height is correct on iPad but incorrect on iPhone:</p>
  
  <pre><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      let screenSize = UIScreen.main.bounds
      let screenHeight = screenSize.height
      self.searchViewHeightConstraint.constant = screenHeight * 0.75
  
      // Correct value on iPad. Incorrect on iPhone.
      print("screenHeight: '\(screenHeight)'") 
  }
  </code></pre>
  
  <p>What is the reason for this inconsistent behaviour between iPhone and iPad and is using <code>NotificationCenter</code> the correct approach to monitoring orientation change?</p>