mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Added support for device auto rotation
This commit is contained in:
parent
fa9e75fe46
commit
151bed4623
2 changed files with 45 additions and 5 deletions
|
|
@ -27,7 +27,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
cameraDelegate = self
|
||||
maximumVideoDuration = 10.0
|
||||
shouldUseDeviceOrientation = true
|
||||
allowAutoRotate = true
|
||||
allowAutoRotate = false
|
||||
|
||||
addButtons()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,14 +281,54 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
// MARK: ViewDidLayoutSubviews
|
||||
|
||||
/// ViewDidLayoutSubviews() Implementation
|
||||
/// ViewDidLayoutSubviews() Implementation
|
||||
|
||||
private func updatePreviewLayer(layer: AVCaptureConnection, orientation: AVCaptureVideoOrientation) {
|
||||
|
||||
layer.videoOrientation = orientation
|
||||
|
||||
previewLayer.frame = self.view.bounds
|
||||
|
||||
}
|
||||
|
||||
/*override open func viewDidLayoutSubviews() {
|
||||
previewLayer.frame = CGRect(x: 0.0, y: 0.0, width: view.bounds.width, height: view.bounds.height)
|
||||
override open func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
} */
|
||||
|
||||
|
||||
if let connection = self.previewLayer?.videoPreviewLayer.connection {
|
||||
|
||||
let currentDevice: UIDevice = UIDevice.current
|
||||
|
||||
let orientation: UIDeviceOrientation = currentDevice.orientation
|
||||
|
||||
let previewLayerConnection : AVCaptureConnection = connection
|
||||
|
||||
if previewLayerConnection.isVideoOrientationSupported {
|
||||
|
||||
switch (orientation) {
|
||||
case .portrait: updatePreviewLayer(layer: previewLayerConnection, orientation: .portrait)
|
||||
|
||||
break
|
||||
|
||||
case .landscapeRight: updatePreviewLayer(layer: previewLayerConnection, orientation: .landscapeLeft)
|
||||
|
||||
break
|
||||
|
||||
case .landscapeLeft: updatePreviewLayer(layer: previewLayerConnection, orientation: .landscapeRight)
|
||||
|
||||
break
|
||||
|
||||
case .portraitUpsideDown: updatePreviewLayer(layer: previewLayerConnection, orientation: .portraitUpsideDown)
|
||||
|
||||
break
|
||||
|
||||
default: updatePreviewLayer(layer: previewLayerConnection, orientation: .portrait)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// MARK: ViewDidAppear
|
||||
|
||||
/// ViewDidAppear(_ animated:) Implementation
|
||||
|
|
|
|||
Loading…
Reference in a new issue