title: iOS - Wrong UIScreen bounds in viewWillTransition for iPad
body: <p>I have to check if my device has changed orientation in iOS 8+.</p>
  
  <p>My approach is:</p>
  
  <pre><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      super.viewWillTransition(to: size, with: coordinator)
  
      let isLand = UIScreen.main.bounds.width &gt; UIScreen.main.bounds.height
  
      coordinator.animate(alongsideTransition: nil) { _ in
          let isLand2 = UIScreen.main.bounds.width &gt; UIScreen.main.bounds.height
  
  
          print("\(isLand) -&gt; \(isLand2)")
      }
  }
  </code></pre>
  
  <p>it works fine in iPhone but in iPad <code>isLand</code> has already the new value which should be after the orientation completion, so:</p>
  
  <p>Portrait > Landscape: <code>true -&gt; true</code></p>
  
  <p>Landscape > Portrait: <code>false -&gt; false</code></p>
  
  <p>According to the documentation the bounds should change with the orientation so it should have a before/after bounds, shouldn't it?</p>
  
  <blockquote>
    <p><strong>UIScreen main bounds:</strong></p>
    
    <p>This rectangle is specified in the current coordinate space, which
    takes into account any interface rotations in effect for the device.
    Therefore, the value of this property may change when the device
    rotates between portrait and landscape orientations.</p>
  </blockquote>
  
  <p>Whereas it works fine both iPhone and iPad if I use the bounds of the current root view controller like this:</p>
  
  <pre><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      super.viewWillTransition(to: size, with: coordinator)
  
      let isLand = UIApplication.shared.keyWindow!.rootViewController!.view.bounds.width &gt; UIApplication.shared.keyWindow!.rootViewController!.view.bounds.height
  
      coordinator.animate(alongsideTransition: nil) { _ in
          let isLand2 = UIApplication.shared.keyWindow!.rootViewController!.view.bounds.width &gt; UIApplication.shared.keyWindow!.rootViewController!.view.bounds.height
  
  
          print("\(isLand) -&gt; \(isLand2)")
      }
  }
  </code></pre>
  
  <p>Portrait > Landscape: <code>false -&gt; true</code></p>
  
  <p>Landscape > Portrait: <code>true -&gt; false</code></p>