From 1335724c58e1a4c26e671312df75653d66b4b4a0 Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Thu, 20 Sep 2018 00:28:07 +0200 Subject: QR code: Support some form of rotation. Signed-off-by: Jason A. Donenfeld --- .../WireGuard/UI/iOS/QRScanViewController.swift | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift index 1725174..6018597 100644 --- a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift @@ -63,6 +63,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 tunnelConfiguration = try WgQuickConfigFileParser.parse(code, name: "Scanned") -- cgit v1.2.3-59-g8ed1b