fix: Fix orientation glitching on first frame
This commit is contained in:
parent
a65b8720bd
commit
bf71901968
@ -10,18 +10,9 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
extension CameraView {
|
||||
/// Returns the current _interface_ orientation of the main window
|
||||
private var windowInterfaceOrientation: UIInterfaceOrientation {
|
||||
if #available(iOS 13.0, *) {
|
||||
return UIApplication.shared.windows.first?.windowScene?.interfaceOrientation ?? .unknown
|
||||
} else {
|
||||
return UIApplication.shared.statusBarOrientation
|
||||
}
|
||||
}
|
||||
|
||||
/// Orientation of the input connection (preview)
|
||||
private var inputOrientation: UIInterfaceOrientation {
|
||||
return windowInterfaceOrientation
|
||||
return .portrait
|
||||
}
|
||||
|
||||
// Orientation of the output connections (photo, video, frame processor)
|
||||
@ -37,15 +28,10 @@ extension CameraView {
|
||||
}
|
||||
|
||||
internal func updateOrientation() {
|
||||
// Updates the Orientation for all rotable connections (outputs) as well as for the preview layer
|
||||
DispatchQueue.main.async {
|
||||
// `windowInterfaceOrientation` and `videoPreviewLayer` should only be accessed from UI thread
|
||||
// Updates the Orientation for all rotable
|
||||
let isMirrored = self.videoDeviceInput?.device.position == .front
|
||||
|
||||
self.videoPreviewLayer.connection?.setInterfaceOrientation(self.inputOrientation)
|
||||
|
||||
let connectionOrientation = self.outputOrientation
|
||||
self.cameraQueue.async {
|
||||
// Run those updates on cameraQueue since they can be blocking.
|
||||
self.captureSession.outputs.forEach { output in
|
||||
output.connections.forEach { connection in
|
||||
@ -58,5 +44,3 @@ extension CameraView {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user