From 7c608cc3bee3a52e3524eba8514af535b48c4df1 Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Thu, 20 Sep 2018 00:28:07 +0200 Subject: [PATCH] Support some form of rotation. Signed-off-by: Jason A. Donenfeld --- .../QRScanViewController.swift | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/WireGuard/ViewControllers/QRScanViewController.swift b/WireGuard/ViewControllers/QRScanViewController.swift index 9cb2522..ad57f77 100644 --- a/WireGuard/ViewControllers/QRScanViewController.swift +++ b/WireGuard/ViewControllers/QRScanViewController.swift @@ -67,6 +67,38 @@ class QRScanViewController: UIViewController { } } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + + if let connection = previewLayer.connection { + + let currentDevice: UIDevice = UIDevice.current + + let orientation: UIDeviceOrientation = currentDevice.orientation + + let previewLayerConnection: AVCaptureConnection = connection + + if previewLayerConnection.isVideoOrientationSupported { + + switch orientation { + case .portrait: + previewLayerConnection.videoOrientation = .portrait + case .landscapeRight: + previewLayerConnection.videoOrientation = .landscapeLeft + case .landscapeLeft: + previewLayerConnection.videoOrientation = .landscapeRight + case .portraitUpsideDown: + previewLayerConnection.videoOrientation = .portraitUpsideDown + default: + previewLayerConnection.videoOrientation = .portrait + + } + } + } + + previewLayer.frame = self.view.bounds + } + func scanDidComplete(withCode code: String) { do { let tunnel = try Tunnel.fromConfig(code, context: viewContext)