Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a property to change video gravity for image captures. #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions Sources/CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum CameraOutputMode {
case stillImage, videoWithMic, videoOnly
}

public enum CameraPreviewMode {
case resizeAspect, resizeAspectFill
}

public enum CaptureResult {
case success(content: CaptureContent)
case failure(Error)
Expand Down Expand Up @@ -296,6 +300,8 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
}
}
}

open var cameraPreviewMode: CameraPreviewMode = .resizeAspectFill

/// Property to check video recording duration when in progress.
open var recordedDuration: CMTime { return movieOutput?.recordedDuration ?? CMTime.zero }
Expand Down Expand Up @@ -1465,7 +1471,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
self._updateCameraDevice(self.cameraDevice)
self._setupOutputs()
self._setupOutputMode(self.cameraOutputMode, oldCameraOutputMode: nil)
self._setupPreviewLayer()
self._setupPreviewLayer(self.cameraPreviewMode)
validCaptureSession.commitConfiguration()
self._updateIlluminationMode(self.flashMode)
self._updateCameraQualityMode(self.cameraOutputQuality)
Expand Down Expand Up @@ -1630,10 +1636,10 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
}
}

fileprivate func _setupPreviewLayer() {
fileprivate func _setupPreviewLayer(_ layerVideoGravity: CameraPreviewMode) {
if let validCaptureSession = captureSession {
previewLayer = AVCaptureVideoPreviewLayer(session: validCaptureSession)
previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
previewLayer?.videoGravity = layerVideoGravity == .resizeAspect ? AVLayerVideoGravity.resizeAspect : AVLayerVideoGravity.resizeAspectFill

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use enum by apple - AVLayerVideoGravity?

}
}

Expand Down