feat: Support rotation (#301)
* feat: Android: Listen to rotation changes * Only change rotation on configuration change * feat: iOS: Support Rotation * Swift lint
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// AVCaptureVideoDataOutput+setOrientation.swift
|
||||
// mrousavy
|
||||
//
|
||||
// Created by Marc Rousavy on 18.01.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import AVFoundation
|
||||
|
||||
extension AVCaptureVideoDataOutput {
|
||||
func setOrientation(forCameraPosition position: AVCaptureDevice.Position) {
|
||||
let isMirrored = position == .front
|
||||
connections.forEach { connection in
|
||||
if connection.isVideoMirroringSupported {
|
||||
connection.automaticallyAdjustsVideoMirroring = false
|
||||
connection.isVideoMirrored = isMirrored
|
||||
}
|
||||
if connection.isVideoOrientationSupported {
|
||||
connection.videoOrientation = .portrait
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user