public override void ViewWillTransitionToSize (CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
base.ViewWillTransitionToSize (toSize, coordinator);
UIDeviceOrientation deviceOrientation = UIDevice.CurrentDevice.Orientation;
if (deviceOrientation.IsPortrait () || deviceOrientation.IsLandscape ()) {
var previewLayer = (AVCaptureVideoPreviewLayer)PreviewView.Layer;
var connection = PreviewLayer.Connection;
if(connection != null)
connection.VideoOrientation = (AVCaptureVideoOrientation)deviceOrientation;
}
}