2022-01-04 08:57:40 -07:00
|
|
|
//
|
|
|
|
// CameraView+Orientation.swift
|
|
|
|
// VisionCamera
|
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 04.01.22.
|
|
|
|
// Copyright © 2022 mrousavy. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension CameraView {
|
|
|
|
/// Orientation of the input connection (preview)
|
|
|
|
private var inputOrientation: UIInterfaceOrientation {
|
2022-11-25 07:39:04 -07:00
|
|
|
return .portrait
|
2022-01-04 08:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Orientation of the output connections (photo, video, frame processor)
|
2023-02-21 07:00:48 -07:00
|
|
|
var outputOrientation: UIInterfaceOrientation {
|
2022-01-04 08:57:40 -07:00
|
|
|
if let userOrientation = orientation as String?,
|
|
|
|
let parsedOrientation = try? UIInterfaceOrientation(withString: userOrientation) {
|
|
|
|
// user is overriding output orientation
|
|
|
|
return parsedOrientation
|
|
|
|
} else {
|
|
|
|
// use same as input orientation
|
|
|
|
return inputOrientation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 07:00:48 -07:00
|
|
|
func updateOrientation() {
|
2022-11-25 07:39:04 -07:00
|
|
|
// Updates the Orientation for all rotable
|
2023-02-13 07:22:45 -07:00
|
|
|
let isMirrored = videoDeviceInput?.device.position == .front
|
2022-01-04 08:57:40 -07:00
|
|
|
|
2023-02-13 07:22:45 -07:00
|
|
|
let connectionOrientation = outputOrientation
|
|
|
|
captureSession.outputs.forEach { output in
|
2022-11-25 07:39:04 -07:00
|
|
|
output.connections.forEach { connection in
|
|
|
|
if connection.isVideoMirroringSupported {
|
|
|
|
connection.automaticallyAdjustsVideoMirroring = false
|
|
|
|
connection.isVideoMirrored = isMirrored
|
2022-01-04 08:57:40 -07:00
|
|
|
}
|
2022-11-25 07:39:04 -07:00
|
|
|
connection.setInterfaceOrientation(connectionOrientation)
|
2022-01-04 08:57:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|