title: How to set Camera View rotation (without using deprecated code)
body: <p>Basically, how does one do this:</p>
  
  <pre><code>    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      [[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)toInterfaceOrientation];
  }
  </code></pre>
  
  <p>without using deprecated code (<code>willRotateToInterfaceOrientation</code>)</p>
  
  <p>My app requires iOS 9, so as long as the new code is backwards compatible that far, I don't need to keep the above code. Apple suggests using <code>viewWillTransitionToSize:withTransitionCoordinator:</code> but I don't know how.</p>
  
  <p>EDIT:</p>
  
  <p>I tried (as suggested by @Matt)</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  override func viewDidLoad() {
      super.viewDidLoad()
      NotificationCenter.default.addObserver(
                                             forName: UIApplication.willChangeStatusBarOrientationNotification,
                                             object: nil, queue: nil) { n in
          // this is where you respond
          if let userInfo = n.userInfo {
              // use the userInfo to find out what the new orientation is...
          }
      }
  }
  }
  </code></pre>
  
  <p>But it throws Use of undeclared identifier 'override' error because it's in swift.</p>