mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
1.2.1 and updated documentation
This commit is contained in:
parent
926e317dbc
commit
faca18d345
5 changed files with 201 additions and 108 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## Version 1.2.1
|
||||||
|
- Minor bug fixes
|
||||||
|
- Updated Documentation
|
||||||
|
|
||||||
## Version 1.2.0
|
## Version 1.2.0
|
||||||
|
|
||||||
- Enabling flash is now a boolean property rather than a function
|
- Enabling flash is now a boolean property rather than a function
|
||||||
|
|
|
||||||
|
|
@ -18,25 +18,27 @@ import UIKit
|
||||||
|
|
||||||
//MARK: Public Protocol Declaration
|
//MARK: Public Protocol Declaration
|
||||||
|
|
||||||
|
/// Delegate for SwiftyCamButton
|
||||||
|
|
||||||
public protocol SwiftyCamButtonDelegate {
|
public protocol SwiftyCamButtonDelegate {
|
||||||
|
|
||||||
// Called when UITapGestureRecognizer begins
|
/// Called when UITapGestureRecognizer begins
|
||||||
|
|
||||||
func buttonWasTapped()
|
func buttonWasTapped()
|
||||||
|
|
||||||
// Called When UILongPressGestureRecognizer enters UIGestureRecognizerState.began
|
/// Called When UILongPressGestureRecognizer enters UIGestureRecognizerState.began
|
||||||
|
|
||||||
func buttonDidBeginLongPress()
|
func buttonDidBeginLongPress()
|
||||||
|
|
||||||
// Called When UILongPressGestureRecognizer enters UIGestureRecognizerState.end
|
/// Called When UILongPressGestureRecognizer enters UIGestureRecognizerState.end
|
||||||
|
|
||||||
func buttonDidEndLongPress()
|
func buttonDidEndLongPress()
|
||||||
|
|
||||||
// Called when the maximum duration is reached
|
/// Called when the maximum duration is reached
|
||||||
|
|
||||||
func longPressDidReachMaximumDuration()
|
func longPressDidReachMaximumDuration()
|
||||||
|
|
||||||
// Sets the maximum duration of the video recording
|
/// Sets the maximum duration of the video recording
|
||||||
|
|
||||||
func setMaxiumVideoDuration() -> Double
|
func setMaxiumVideoDuration() -> Double
|
||||||
}
|
}
|
||||||
|
|
@ -44,13 +46,15 @@ public protocol SwiftyCamButtonDelegate {
|
||||||
// MARK: Public View Declaration
|
// MARK: Public View Declaration
|
||||||
|
|
||||||
|
|
||||||
|
/// UIButton Subclass for Capturing Photo and Video with SwiftyCamViewController
|
||||||
|
|
||||||
open class SwiftyCamButton: UIButton {
|
open class SwiftyCamButton: UIButton {
|
||||||
|
|
||||||
// Delegate variable
|
/// Delegate variable
|
||||||
|
|
||||||
public var delegate: SwiftyCamButtonDelegate?
|
public var delegate: SwiftyCamButtonDelegate?
|
||||||
|
|
||||||
// Maximum duration variable
|
/// Maximum duration variable
|
||||||
|
|
||||||
fileprivate var timer : Timer?
|
fileprivate var timer : Timer?
|
||||||
|
|
||||||
|
|
@ -64,13 +68,13 @@ open class SwiftyCamButton: UIButton {
|
||||||
createGestureRecognizers()
|
createGestureRecognizers()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UITapGestureRecognizer Function
|
/// UITapGestureRecognizer Function
|
||||||
|
|
||||||
@objc fileprivate func Tap() {
|
@objc fileprivate func Tap() {
|
||||||
self.delegate?.buttonWasTapped()
|
self.delegate?.buttonWasTapped()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UILongPressGestureRecognizer Function
|
/// UILongPressGestureRecognizer Function
|
||||||
|
|
||||||
@objc fileprivate func LongPress(_ sender:UILongPressGestureRecognizer!) {
|
@objc fileprivate func LongPress(_ sender:UILongPressGestureRecognizer!) {
|
||||||
if (sender.state == UIGestureRecognizerState.ended) {
|
if (sender.state == UIGestureRecognizerState.ended) {
|
||||||
|
|
|
||||||
|
|
@ -19,38 +19,63 @@ import AVFoundation
|
||||||
|
|
||||||
// MARK: View Controller Declaration
|
// MARK: View Controller Declaration
|
||||||
|
|
||||||
|
/// A UIViewController Camera View Subclass
|
||||||
|
|
||||||
open class SwiftyCamViewController: UIViewController {
|
open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: Enumeration Declaration
|
// MARK: Enumeration Declaration
|
||||||
|
|
||||||
|
/**
|
||||||
|
Enumeration for Camera Selection
|
||||||
|
|
||||||
// Possible Camera Selection Posibilities
|
- rear: Camera on the back of the device.
|
||||||
|
- front: Camera on the front of the device.
|
||||||
|
*/
|
||||||
|
|
||||||
public enum CameraSelection {
|
public enum CameraSelection {
|
||||||
case rear
|
case rear
|
||||||
case front
|
case front
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for Setting Video Quality of Capture Session
|
/**
|
||||||
// Corresponds to the AVCaptureSessionPreset String
|
|
||||||
// Global Variables Declared in AVFoundation
|
|
||||||
// AVCaptureSessionPresetPhoto is not supported as it does not support video capture
|
Enumeration for video quality of the capture session. Corresponds to a AVCaptureSessionPreset
|
||||||
// AVCaptureSessionPreset320x240 is not supported as it is the incorrect aspect ratio
|
|
||||||
|
- high: AVCaptureSessionPresetHigh
|
||||||
|
- medium: AVCaptureSessionPresetMedium
|
||||||
|
- low: AVCaptureSessionPresetLow
|
||||||
|
- resolution352x288: AVCaptureSessionPreset352x288
|
||||||
|
- resolution640x480: AVCaptureSessionPreset640x480
|
||||||
|
- resolution1280x720: AVCaptureSessionPreset1280x720
|
||||||
|
- resolution1920x1080: AVCaptureSessionPreset1920x1080
|
||||||
|
- resolution3840x2160: AVCaptureSessionPreset3840x2160
|
||||||
|
- iframe960x540: AVCaptureSessionPresetiFrame960x540
|
||||||
|
- iframe1280x720: AVCaptureSessionPresetiFrame1280x720
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
public enum VideoQuality {
|
public enum VideoQuality {
|
||||||
case high // AVCaptureSessionPresetHigh
|
case high
|
||||||
case medium // AVCaptureSessionPresetMedium
|
case medium
|
||||||
case low // AVCaptureSessionPresetLow
|
case low
|
||||||
case resolution352x288 // AVCaptureSessionPreset352x288
|
case resolution352x288
|
||||||
case resolution640x480 // AVCaptureSessionPreset640x480
|
case resolution640x480
|
||||||
case resolution1280x720 // AVCaptureSessionPreset1280x720
|
case resolution1280x720
|
||||||
case resolution1920x1080 // AVCaptureSessionPreset1920x1080
|
case resolution1920x1080
|
||||||
case resolution3840x2160 // AVCaptureSessionPreset3840x2160
|
case resolution3840x2160
|
||||||
case iframe960x540 // AVCaptureSessionPresetiFrame960x540
|
case iframe960x540
|
||||||
case iframe1280x720 // AVCaptureSessionPresetiFrame1280x720
|
case iframe1280x720
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result from the AVCaptureSession Setup
|
/**
|
||||||
|
|
||||||
|
Result from the AVCaptureSession Setup
|
||||||
|
|
||||||
|
- success: success
|
||||||
|
- notAuthorized: User denied access to Camera of Microphone
|
||||||
|
- configurationFailed: Unknown error
|
||||||
|
*/
|
||||||
|
|
||||||
fileprivate enum SessionSetupResult {
|
fileprivate enum SessionSetupResult {
|
||||||
case success
|
case success
|
||||||
|
|
@ -60,113 +85,102 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: Public Variable Declarations
|
// MARK: Public Variable Declarations
|
||||||
|
|
||||||
// Public Camera Delegate for the Custom View Controller Subclass
|
/// Public Camera Delegate for the Custom View Controller Subclass
|
||||||
|
|
||||||
public var cameraDelegate: SwiftyCamViewControllerDelegate?
|
public var cameraDelegate: SwiftyCamViewControllerDelegate?
|
||||||
|
|
||||||
// Used to set the maximum duration of the video capture
|
/// Maxiumum video duration if SwiftyCamButton is used
|
||||||
// Only used for SwiftyCamButton
|
|
||||||
// Value of 0.0 does not enforce a fixed duration
|
|
||||||
|
|
||||||
public var kMaximumVideoDuration : Double = 0.0
|
public var kMaximumVideoDuration : Double = 0.0
|
||||||
|
|
||||||
// Quality of rear facing camera
|
/// Video capture quality
|
||||||
// Quality of front caing quality will always be VideoQuality.high
|
|
||||||
|
|
||||||
public var videoQuality : VideoQuality = .high
|
public var videoQuality : VideoQuality = .high
|
||||||
|
|
||||||
// Sets whether camera flash will be used to take photo
|
/// Sets whether flash is enabled for photo and video capture
|
||||||
// For photos, camera flash will be enabled when photo is taken
|
|
||||||
// For videos, camera flash will be enabled for the duration of the video
|
|
||||||
// Not currently supported for front facing camera
|
|
||||||
|
|
||||||
public var flashEnabled = false
|
public var flashEnabled = false
|
||||||
|
|
||||||
// Sets whether Pinch to Zoom is supported for the capture session
|
/// Sets whether Pinch to Zoom is supported for the capture session
|
||||||
// Pinch to zoom not supported on front facing camera
|
|
||||||
|
|
||||||
public var pinchToZoom = true
|
public var pinchToZoom = true
|
||||||
|
|
||||||
// Sets whether Tap to Focus is supported for the capture session
|
/// Sets whether Tap to Focus is supported for the capture session
|
||||||
// Tap to Focus is not supported on front facing camera
|
|
||||||
// Tapping the capture session will call the SwiftyCamViewControllerDelegate delegate function SwiftyCamDidFocusAtPoint(focusPoint: CGPoint)
|
|
||||||
|
|
||||||
public var tapToFocus = true
|
public var tapToFocus = true
|
||||||
|
|
||||||
// Sets whether SwiftyCam will prompt a user to the App Settings Screen if Camera or Microphone access is not authorized
|
/// Sets whether SwiftyCam will prompt a user to the App Settings Screen if Camera or Microphone access is not authorized
|
||||||
// If set to false and Camera/Microphone is not authorized, SwiftyCamViewControllerDelegate delegate
|
|
||||||
// function SwiftyCamDidFailCameraPermissionSettings() will be called
|
|
||||||
|
|
||||||
public var promptToAppPrivacySettings = true
|
public var promptToAppPrivacySettings = true
|
||||||
|
|
||||||
|
|
||||||
// MARK: Public Get-only Variable Declarations
|
// MARK: Public Get-only Variable Declarations
|
||||||
|
|
||||||
// Returns a boolean if the torch (flash) is currently enabled
|
/// Returns true if the torch (flash) is currently enabled
|
||||||
|
|
||||||
private(set) public var isCameraFlashOn = false
|
private(set) public var isCameraFlashOn = false
|
||||||
|
|
||||||
// Returns a boolean if video is currently being recorded
|
/// Returns true if video is currently being recorded
|
||||||
|
|
||||||
private(set) public var isVideRecording = false
|
private(set) public var isVideRecording = false
|
||||||
|
|
||||||
// Returns a boolean if the capture session is currently running
|
/// Returns true if the capture session is currently running
|
||||||
|
|
||||||
private(set) public var isSessionRunning = false
|
private(set) public var isSessionRunning = false
|
||||||
|
|
||||||
// Returns a CameraSelection enum for the currently utilized camera
|
/// Returns the CameraSelection corresponding to the currently utilized camera
|
||||||
|
|
||||||
private(set) public var currentCamera = CameraSelection.rear
|
private(set) public var currentCamera = CameraSelection.rear
|
||||||
|
|
||||||
// MARK: Private Constant Declarations
|
// MARK: Private Constant Declarations
|
||||||
|
|
||||||
// Current Capture Session
|
/// Current Capture Session
|
||||||
|
|
||||||
fileprivate let session = AVCaptureSession()
|
fileprivate let session = AVCaptureSession()
|
||||||
|
|
||||||
// Serial queue used for setting up session
|
/// Serial queue used for setting up session
|
||||||
|
|
||||||
fileprivate let sessionQueue = DispatchQueue(label: "session queue", attributes: [])
|
fileprivate let sessionQueue = DispatchQueue(label: "session queue", attributes: [])
|
||||||
|
|
||||||
// MARK: Private Variable Declarations
|
// MARK: Private Variable Declarations
|
||||||
|
|
||||||
// Variable for storing current zoom scale
|
/// Variable for storing current zoom scale
|
||||||
|
|
||||||
fileprivate var zoomScale = CGFloat(1.0)
|
fileprivate var zoomScale = CGFloat(1.0)
|
||||||
|
|
||||||
// Variable for storing initial zoom scale before Pinch to Zoom begins
|
/// Variable for storing initial zoom scale before Pinch to Zoom begins
|
||||||
|
|
||||||
fileprivate var beginZoomScale = CGFloat(1.0)
|
fileprivate var beginZoomScale = CGFloat(1.0)
|
||||||
|
|
||||||
// Variable to store result of capture session setup
|
/// Variable to store result of capture session setup
|
||||||
|
|
||||||
fileprivate var setupResult = SessionSetupResult.success
|
fileprivate var setupResult = SessionSetupResult.success
|
||||||
|
|
||||||
// BackgroundID variable for video recording
|
/// BackgroundID variable for video recording
|
||||||
|
|
||||||
fileprivate var backgroundRecordingID : UIBackgroundTaskIdentifier? = nil
|
fileprivate var backgroundRecordingID : UIBackgroundTaskIdentifier? = nil
|
||||||
|
|
||||||
// Video Input variable
|
/// Video Input variable
|
||||||
|
|
||||||
fileprivate var videoDeviceInput : AVCaptureDeviceInput!
|
fileprivate var videoDeviceInput : AVCaptureDeviceInput!
|
||||||
|
|
||||||
// Movie File Output variable
|
/// Movie File Output variable
|
||||||
|
|
||||||
fileprivate var movieFileOutput : AVCaptureMovieFileOutput?
|
fileprivate var movieFileOutput : AVCaptureMovieFileOutput?
|
||||||
|
|
||||||
// Photo File Output variable
|
/// Photo File Output variable
|
||||||
|
|
||||||
fileprivate var photoFileOutput : AVCaptureStillImageOutput?
|
fileprivate var photoFileOutput : AVCaptureStillImageOutput?
|
||||||
|
|
||||||
// Video Device variable
|
/// Video Device variable
|
||||||
|
|
||||||
fileprivate var videoDevice : AVCaptureDevice?
|
fileprivate var videoDevice : AVCaptureDevice?
|
||||||
|
|
||||||
// PreviewView for the capture session
|
/// PreviewView for the capture session
|
||||||
|
|
||||||
fileprivate var previewLayer : PreviewView!
|
fileprivate var previewLayer : PreviewView!
|
||||||
|
|
||||||
// Disable view autorotation for forced portrait recorindg
|
/// Disable view autorotation for forced portrait recorindg
|
||||||
|
|
||||||
open override var shouldAutorotate: Bool {
|
open override var shouldAutorotate: Bool {
|
||||||
return false
|
return false
|
||||||
|
|
@ -180,7 +194,8 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// Add Pinch Gesture Recognizer for pinch to zoom
|
// Add Pinch Gesture Recognizer for pinch to zoom
|
||||||
|
|
||||||
addGestureRecognizers(toView: previewLayer)
|
addGestureRecognizersTo(view: previewLayer)
|
||||||
|
|
||||||
self.view.addSubview(previewLayer)
|
self.view.addSubview(previewLayer)
|
||||||
previewLayer.session = session
|
previewLayer.session = session
|
||||||
|
|
||||||
|
|
@ -254,7 +269,13 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: Public Functions
|
// MARK: Public Functions
|
||||||
|
|
||||||
// Capture photo from session
|
/**
|
||||||
|
|
||||||
|
Capture photo from current session
|
||||||
|
|
||||||
|
UIImage will be returned with the SwiftyCamViewControllerDelegate function SwiftyCamDidTakePhoto(photo:)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
public func takePhoto() {
|
public func takePhoto() {
|
||||||
|
|
||||||
|
|
@ -286,7 +307,13 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin recording video
|
/**
|
||||||
|
|
||||||
|
Begin recording video of current session
|
||||||
|
|
||||||
|
SwiftyCamViewControllerDelegate function SwiftyCamDidBeginRecordingVideo() will be called
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
public func startVideoRecording() {
|
public func startVideoRecording() {
|
||||||
guard let movieFileOutput = self.movieFileOutput else {
|
guard let movieFileOutput = self.movieFileOutput else {
|
||||||
|
|
@ -328,7 +355,15 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop video recording
|
/**
|
||||||
|
|
||||||
|
Stop video recording video of current session
|
||||||
|
|
||||||
|
SwiftyCamViewControllerDelegate function SwiftyCamDidFinishRecordingVideo() will be called
|
||||||
|
|
||||||
|
When video has finished processing, the URL to the video location will be returned by SwiftyCamDidFinishProcessingVideoAt(url:)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
public func endVideoRecording() {
|
public func endVideoRecording() {
|
||||||
if self.movieFileOutput?.isRecording == true {
|
if self.movieFileOutput?.isRecording == true {
|
||||||
|
|
@ -339,7 +374,14 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch between front and rear camera
|
/**
|
||||||
|
|
||||||
|
Switch between front and rear camera
|
||||||
|
|
||||||
|
SwiftyCamViewControllerDelegate function SwiftyCamDidSwitchCameras(camera: will be return the current camera selection
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
public func switchCamera() {
|
public func switchCamera() {
|
||||||
guard isVideRecording != true else {
|
guard isVideRecording != true else {
|
||||||
|
|
@ -376,8 +418,8 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
disableFlash()
|
disableFlash()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override Touches Began
|
|
||||||
// Used for Tap to Focus
|
/// Override Touches Began for Tap to Focus
|
||||||
|
|
||||||
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
guard tapToFocus == true && currentCamera == .rear else {
|
guard tapToFocus == true && currentCamera == .rear else {
|
||||||
|
|
@ -412,7 +454,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: Private Functions
|
// MARK: Private Functions
|
||||||
|
|
||||||
// Configure session, add inputs and outputs
|
/// Configure session, add inputs and outputs
|
||||||
|
|
||||||
fileprivate func configureSession() {
|
fileprivate func configureSession() {
|
||||||
guard setupResult == .success else {
|
guard setupResult == .success else {
|
||||||
|
|
@ -428,9 +470,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure preset
|
|
||||||
// Front facing camera will always be set to VideoQuality.high
|
// Front facing camera will always be set to VideoQuality.high
|
||||||
// If set video quality is not supported, videoQuality variable will be set to VideoQuality.high
|
// If set video quality is not supported, videoQuality variable will be set to VideoQuality.high
|
||||||
|
/// Configure image quality preset
|
||||||
|
|
||||||
fileprivate func configureVideoPreset() {
|
fileprivate func configureVideoPreset() {
|
||||||
|
|
||||||
|
|
@ -445,7 +487,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Video Inputs
|
/// Add Video Inputs
|
||||||
|
|
||||||
fileprivate func addVideoInput() {
|
fileprivate func addVideoInput() {
|
||||||
switch currentCamera {
|
switch currentCamera {
|
||||||
|
|
@ -499,7 +541,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Audio Inputs
|
/// Add Audio Inputs
|
||||||
|
|
||||||
fileprivate func addAudioInput() {
|
fileprivate func addAudioInput() {
|
||||||
do {
|
do {
|
||||||
|
|
@ -518,7 +560,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure Movie Output
|
/// Configure Movie Output
|
||||||
|
|
||||||
fileprivate func configureVideoOutput() {
|
fileprivate func configureVideoOutput() {
|
||||||
let movieFileOutput = AVCaptureMovieFileOutput()
|
let movieFileOutput = AVCaptureMovieFileOutput()
|
||||||
|
|
@ -534,7 +576,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure Photo Output
|
/// Configure Photo Output
|
||||||
|
|
||||||
fileprivate func configurePhotoOutput() {
|
fileprivate func configurePhotoOutput() {
|
||||||
let photoFileOutput = AVCaptureStillImageOutput()
|
let photoFileOutput = AVCaptureStillImageOutput()
|
||||||
|
|
@ -546,7 +588,13 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Image from Image Data
|
/**
|
||||||
|
Returns a UIImage from Image Data.
|
||||||
|
|
||||||
|
- Parameter imageData: Image Data returned from capturing photo from the capture session.
|
||||||
|
|
||||||
|
- Returns: UIImage from the image data, adjusted for proper orientation.
|
||||||
|
*/
|
||||||
|
|
||||||
fileprivate func processPhoto(_ imageData: Data) -> UIImage {
|
fileprivate func processPhoto(_ imageData: Data) -> UIImage {
|
||||||
let dataProvider = CGDataProvider(data: imageData as CFData)
|
let dataProvider = CGDataProvider(data: imageData as CFData)
|
||||||
|
|
@ -566,7 +614,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return image
|
return image
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle zoom gesture
|
/// Handle pinch gesture
|
||||||
|
|
||||||
@objc fileprivate func zoomGesture(pinch: UIPinchGestureRecognizer) {
|
@objc fileprivate func zoomGesture(pinch: UIPinchGestureRecognizer) {
|
||||||
guard pinchToZoom == true && self.currentCamera == .rear else {
|
guard pinchToZoom == true && self.currentCamera == .rear else {
|
||||||
|
|
@ -591,15 +639,20 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add pinch Gesture
|
/**
|
||||||
|
Add pinch gesture recognizer to currentView
|
||||||
|
|
||||||
fileprivate func addGestureRecognizers(toView: UIView) {
|
- Parameter view: View to add gesture recognzier
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
fileprivate func addGestureRecognizersTo(view: UIView) {
|
||||||
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(zoomGesture(pinch:)))
|
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(zoomGesture(pinch:)))
|
||||||
pinchGesture.delegate = self
|
pinchGesture.delegate = self
|
||||||
toView.addGestureRecognizer(pinchGesture)
|
view.addGestureRecognizer(pinchGesture)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Handle Denied App Privacy Settings
|
/// Handle Denied App Privacy Settings
|
||||||
|
|
||||||
fileprivate func promptToAppSettings() {
|
fileprivate func promptToAppSettings() {
|
||||||
guard promptToAppPrivacySettings == true else {
|
guard promptToAppPrivacySettings == true else {
|
||||||
|
|
@ -628,7 +681,13 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set AVCapturePreset from VideoQuality enum
|
/**
|
||||||
|
Returns an AVCapturePreset from VideoQuality Enumeration
|
||||||
|
|
||||||
|
- Parameter quality: ViewQuality enum
|
||||||
|
|
||||||
|
- Returns: String representing a AVCapturePreset
|
||||||
|
*/
|
||||||
|
|
||||||
fileprivate func videoInputPresetFromVideoQuality(quality: VideoQuality) -> String {
|
fileprivate func videoInputPresetFromVideoQuality(quality: VideoQuality) -> String {
|
||||||
switch quality {
|
switch quality {
|
||||||
|
|
@ -659,7 +718,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable flash
|
/// Enable flash
|
||||||
|
|
||||||
fileprivate func enableFlash() {
|
fileprivate func enableFlash() {
|
||||||
if self.isCameraFlashOn == false {
|
if self.isCameraFlashOn == false {
|
||||||
|
|
@ -667,7 +726,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable flash
|
/// Disable flash
|
||||||
|
|
||||||
fileprivate func disableFlash() {
|
fileprivate func disableFlash() {
|
||||||
if self.isCameraFlashOn == true {
|
if self.isCameraFlashOn == true {
|
||||||
|
|
@ -675,6 +734,8 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggles between enabling and disabling flash
|
||||||
|
|
||||||
fileprivate func toggleFlash() {
|
fileprivate func toggleFlash() {
|
||||||
guard self.currentCamera == .rear else {
|
guard self.currentCamera == .rear else {
|
||||||
// Flash is not supported for front facing camera
|
// Flash is not supported for front facing camera
|
||||||
|
|
@ -707,33 +768,32 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
||||||
|
|
||||||
// Sets the maximum duration of the SwiftyCamButton
|
/// Sets the maximum duration of the SwiftyCamButton
|
||||||
// Value of 0.0 will not enforce any maximum
|
|
||||||
|
|
||||||
public func setMaxiumVideoDuration() -> Double {
|
public func setMaxiumVideoDuration() -> Double {
|
||||||
return kMaximumVideoDuration
|
return kMaximumVideoDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set UITapGesture to take photo
|
/// Set UITapGesture to take photo
|
||||||
|
|
||||||
public func buttonWasTapped() {
|
public func buttonWasTapped() {
|
||||||
takePhoto()
|
takePhoto()
|
||||||
}
|
}
|
||||||
|
|
||||||
// set UILongPressGesture start to begin video
|
/// Set UILongPressGesture start to begin video
|
||||||
|
|
||||||
public func buttonDidBeginLongPress() {
|
public func buttonDidBeginLongPress() {
|
||||||
startVideoRecording()
|
startVideoRecording()
|
||||||
}
|
}
|
||||||
|
|
||||||
// set UILongPressGesture begin to begin end video
|
/// Set UILongPressGesture begin to begin end video
|
||||||
|
|
||||||
|
|
||||||
public func buttonDidEndLongPress() {
|
public func buttonDidEndLongPress() {
|
||||||
endVideoRecording()
|
endVideoRecording()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called if maximum duration is reached
|
/// Called if maximum duration is reached
|
||||||
|
|
||||||
public func longPressDidReachMaximumDuration() {
|
public func longPressDidReachMaximumDuration() {
|
||||||
endVideoRecording()
|
endVideoRecording()
|
||||||
|
|
@ -744,6 +804,8 @@ extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
||||||
|
|
||||||
extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
||||||
|
|
||||||
|
/// Process newly captured video and write it to temporary directory
|
||||||
|
|
||||||
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
|
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
|
||||||
if let currentBackgroundRecordingID = backgroundRecordingID {
|
if let currentBackgroundRecordingID = backgroundRecordingID {
|
||||||
backgroundRecordingID = UIBackgroundTaskInvalid
|
backgroundRecordingID = UIBackgroundTaskInvalid
|
||||||
|
|
@ -765,7 +827,7 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
||||||
|
|
||||||
extension SwiftyCamViewController : UIGestureRecognizerDelegate {
|
extension SwiftyCamViewController : UIGestureRecognizerDelegate {
|
||||||
|
|
||||||
// Set beginZoomScale when pinch begins
|
/// Set beginZoomScale when pinch begins
|
||||||
|
|
||||||
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||||
if gestureRecognizer.isKind(of: UIPinchGestureRecognizer.self) {
|
if gestureRecognizer.isKind(of: UIPinchGestureRecognizer.self) {
|
||||||
|
|
|
||||||
|
|
@ -18,44 +18,67 @@ import UIKit
|
||||||
|
|
||||||
// MARK: Public Protocol Declaration
|
// MARK: Public Protocol Declaration
|
||||||
|
|
||||||
|
/// Delegate for SwiftyCamViewController
|
||||||
|
|
||||||
public protocol SwiftyCamViewControllerDelegate {
|
public protocol SwiftyCamViewControllerDelegate {
|
||||||
|
|
||||||
// Called when SwiftyCamViewController takes a photo. Returns a UIImage
|
/**
|
||||||
|
SwiftyCamViewControllerDelegate function called when the takePhoto() function is called
|
||||||
|
|
||||||
|
- Parameter photo: UIImage captured from the current session
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
func SwiftyCamDidTakePhoto(_ photo:UIImage)
|
func SwiftyCamDidTakePhoto(_ photo:UIImage)
|
||||||
|
|
||||||
// Called when SwiftyCamViewController begins recording video
|
/// SwiftyCamViewControllerDelegate function called when SwiftyCamViewController begins recording video
|
||||||
|
|
||||||
func SwiftyCamDidBeginRecordingVideo()
|
func SwiftyCamDidBeginRecordingVideo()
|
||||||
|
|
||||||
// Called when SwiftyCamViewController finishes recording video
|
/// SwiftyCamViewControllerDelegate function called when SwiftyCamViewController finishes recording video
|
||||||
|
|
||||||
func SwiftyCamDidFinishRecordingVideo()
|
func SwiftyCamDidFinishRecordingVideo()
|
||||||
|
|
||||||
// Called when SwiftyCamViewController is done processing video. Returns the URL of the video location
|
|
||||||
|
/**
|
||||||
|
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController is done processing video
|
||||||
|
|
||||||
|
- Parameter url: URL location of video in temporary directory
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL)
|
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL)
|
||||||
|
|
||||||
// Called when SwiftyCamViewController switches between front or rear camera. Return the current CameraSelection
|
/**
|
||||||
|
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController switches between front or rear camera
|
||||||
|
|
||||||
|
- Parameter camera: Current camera selection
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection)
|
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection)
|
||||||
|
|
||||||
// Called when SwiftyCamViewController view is tapped and begins focusing at that point
|
/**
|
||||||
// Will only be called if tapToFocus is set to true
|
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController view is tapped and begins focusing at that point
|
||||||
// Not supported on front facing camera
|
|
||||||
// Returns the CGPoint tap location
|
- Parameter focusPoint: Location in view where camera focused
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint)
|
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint)
|
||||||
|
|
||||||
// Called when SwiftyCamViewController view changes zoom level
|
/**
|
||||||
// Will only be called if pinchToZoom is set to true
|
SwiftyCamViewControllerDelegate function called when when SwiftyCamViewController view changes zoom level
|
||||||
// Not supported on front facing camera
|
|
||||||
// Returns the current zoomLevel
|
- Parameter zoomLevel: Current zoom level
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat)
|
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat)
|
||||||
|
|
||||||
// Called if app permissions are denied for either Camera or Microphone
|
|
||||||
// Only called if promptToAppPrivacySettings is set to false
|
/// SwiftyCamViewControllerDelegate function called if app permissions are denied for either Camera or Microphone
|
||||||
|
|
||||||
func SwiftyCamDidFailCameraPermissionSettings()
|
func SwiftyCamDidFailCameraPermissionSettings()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'SwiftyCam'
|
s.name = 'SwiftyCam'
|
||||||
s.version = '1.2.0'
|
s.version = '1.2.1'
|
||||||
s.summary = 'A Simple, Snapchat-style camera Framework written in Swift'
|
s.summary = 'A Simple, Snapchat-style camera Framework written in Swift'
|
||||||
s.ios.deployment_target = '8.0'
|
s.ios.deployment_target = '8.0'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue