react-native-vision-camera/ios/Extensions/AVCaptureConnection+setInterfaceOrientation.swift
Marc Rousavy ef455df865
feat: Support rotation (#301)
* feat: Android: Listen to rotation changes

* Only change rotation on configuration change

* feat: iOS: Support Rotation

* Swift lint
2021-07-26 11:32:58 +02:00

35 lines
895 B
Swift

//
// AVCaptureConnection+setInterfaceOrientation.swift
// VisionCamera
//
// Created by Marc Rousavy on 26.07.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureConnection {
/**
Sets the `videoOrientation` to the given `orientation` if video orientation setting is supported.
*/
func setInterfaceOrientation(_ orientation: UIInterfaceOrientation) {
if isVideoOrientationSupported {
switch orientation {
case .portrait:
videoOrientation = .portrait
case .portraitUpsideDown:
videoOrientation = .portraitUpsideDown
case .landscapeLeft:
videoOrientation = .landscapeLeft
case .landscapeRight:
videoOrientation = .landscapeRight
case .unknown:
fallthrough
@unknown default:
videoOrientation = .portrait
}
}
}
}