Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/CodeScanner/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension CodeScannerView {
#else

var captureSession: AVCaptureSession?
var previewLayer: AVCaptureVideoPreviewLayer!
var previewLayer: AVCaptureVideoPreviewLayer?

private lazy var viewFinder: UIImageView? = {
guard let image = UIImage(named: "viewfinder", in: .module, with: nil) else {
Expand Down Expand Up @@ -148,7 +148,7 @@ extension CodeScannerView {

@objc func updateOrientation() {
guard let orientation = view.window?.windowScene?.interfaceOrientation else { return }
guard let connection = captureSession?.connections.last, connection.isVideoOrientationSupported else { return }
guard let previewLayer, let connection = previewLayer.connection, connection.isVideoOrientationSupported else { return }
switch orientation {
case .portrait:
connection.videoOrientation = .portrait
Expand Down Expand Up @@ -183,8 +183,10 @@ extension CodeScannerView {
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
}

let previewLayer = self.previewLayer!
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = .resizeAspectFill
updateOrientation()
view.layer.addSublayer(previewLayer)
addViewFinder()

Expand Down