mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +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
|
cameraDelegate = self
|
||||||
maximumVideoDuration = 10.0
|
maximumVideoDuration = 10.0
|
||||||
shouldUseDeviceOrientation = true
|
shouldUseDeviceOrientation = true
|
||||||
allowAutoRotate = true
|
allowAutoRotate = false
|
||||||
|
|
||||||
addButtons()
|
addButtons()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -281,14 +281,54 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: ViewDidLayoutSubviews
|
// MARK: ViewDidLayoutSubviews
|
||||||
|
|
||||||
|
/// ViewDidLayoutSubviews() Implementation
|
||||||
/// ViewDidLayoutSubviews() Implementation
|
/// ViewDidLayoutSubviews() Implementation
|
||||||
|
|
||||||
|
private func updatePreviewLayer(layer: AVCaptureConnection, orientation: AVCaptureVideoOrientation) {
|
||||||
|
|
||||||
|
layer.videoOrientation = orientation
|
||||||
|
|
||||||
|
previewLayer.frame = self.view.bounds
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*override open func viewDidLayoutSubviews() {
|
override open func viewDidLayoutSubviews() {
|
||||||
previewLayer.frame = CGRect(x: 0.0, y: 0.0, width: view.bounds.width, height: view.bounds.height)
|
|
||||||
super.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
|
// MARK: ViewDidAppear
|
||||||
|
|
||||||
/// ViewDidAppear(_ animated:) Implementation
|
/// ViewDidAppear(_ animated:) Implementation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue