mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Added support for capture in landscape orientation
This commit is contained in:
parent
474b1b53a8
commit
5caeaa73fb
1 changed files with 20 additions and 0 deletions
|
|
@ -288,6 +288,12 @@ open class SwiftyCamViewController: UIViewController {
|
|||
// Begin Session
|
||||
self.session.startRunning()
|
||||
self.isSessionRunning = self.session.isRunning
|
||||
|
||||
// Preview layer video orientation can be set only after the connection is created
|
||||
DispatchQueue.main.async {
|
||||
self.previewLayer.videoPreviewLayer.connection?.videoOrientation = self.getPreviewLayerOrientation()
|
||||
}
|
||||
|
||||
case .notAuthorized:
|
||||
// Prompt to App Settings
|
||||
self.promptToAppSettings()
|
||||
|
|
@ -676,6 +682,20 @@ open class SwiftyCamViewController: UIViewController {
|
|||
self.deviceOrientation = UIDevice.current.orientation
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func getPreviewLayerOrientation() -> AVCaptureVideoOrientation {
|
||||
// Depends on layout orientation, not device orientation
|
||||
switch UIApplication.shared.statusBarOrientation {
|
||||
case .portrait, .unknown:
|
||||
return AVCaptureVideoOrientation.portrait
|
||||
case .landscapeLeft:
|
||||
return AVCaptureVideoOrientation.landscapeLeft
|
||||
case .landscapeRight:
|
||||
return AVCaptureVideoOrientation.landscapeRight
|
||||
case .portraitUpsideDown:
|
||||
return AVCaptureVideoOrientation.portraitUpsideDown
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
|
||||
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return previewLayer!.videoPreviewLayer.connection.videoOrientation }
|
||||
|
|
|
|||
Loading…
Reference in a new issue