Fixed issue with front flash not turning on in time

This commit is contained in:
Andrew Walz 2017-01-13 17:05:51 -07:00
parent 73bbfa0078
commit da8f7ba858
4 changed files with 91 additions and 109 deletions

View file

@ -25,7 +25,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
cameraDelegate = self
kMaximumVideoDuration = 10.0
maximumVideoDuration = 10.0
doubleTapCameraSwitch = true
addButtons()
@ -39,12 +39,12 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
super.viewDidAppear(animated)
}
func SwiftyCamDidTakePhoto(_ photo: UIImage) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage) {
let newVC = PhotoViewController(image: photo)
self.present(newVC, animated: true, completion: nil)
}
func SwiftyCamDidBeginRecordingVideo() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
print("Did Begin Recording")
captureButton.growButton()
UIView.animate(withDuration: 0.25, animations: {
@ -53,7 +53,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
})
}
func SwiftyCamDidFinishRecordingVideo() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
print("Did finish Recording")
captureButton.shrinkButton()
UIView.animate(withDuration: 0.25, animations: {
@ -62,14 +62,14 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
})
}
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL) {
let newVC = VideoViewController(videoURL: url)
self.present(newVC, animated: true, completion: nil)
}
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint) {
let focusView = UIImageView(image: #imageLiteral(resourceName: "focus"))
focusView.center = focusPoint
focusView.center = point
focusView.alpha = 0.0
view.addSubview(focusView)
@ -86,11 +86,11 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
})
}
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat) {
print(zoomLevel)
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
print(zoom)
}
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
print(camera)
}

View file

@ -116,10 +116,10 @@ Capturing Video is just as easy. To begin recording video, call the `startVideoR
startVideoRecording()
```
To end the capture of a video, call the `endVideoRecordingFunction`:
To end the capture of a video, call the `stopVideoRecording` function:
```swift
endVideoRecording()
stopVideoRecording()
```
@ -141,41 +141,41 @@ class MyCameraViewController : SwiftyCamViewController, SwiftyCamViewControllerD
####Delegate methods:
```swift
func SwiftyCamDidTakePhoto(_ photo: UIImage) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage) {
// Called when takePhoto() is called or if a SwiftyCamButton initiates a tap gesture
// Returns a UIImage captured from the current session
}
func SwiftyCamDidBeginRecordingVideo() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
// Called when startVideoRecording() is called
// Called if a SwiftyCamButton begins a long press gesture
}
func SwiftyCamDidFinishRecordingVideo() {
// Called when endVideoRecording() is called
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
// Called when stopVideoRecording() is called
// Called if a SwiftyCamButton ends a long press gesture
}
}
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
// Called when endVideoRecording() is called and the video is finished processing
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL) {
// Called when stopVideoRecording() is called and the video is finished processing
// Returns a URL in the temporary directory where video is stored
}
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint) {
// Called when a user initiates a tap gesture on the preview layer
// Will only be called if tapToFocus = true
// Returns a CGPoint of the tap location on the preview layer
}
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
// Called when a user initiates a pinch gesture on the preview layer
// Will only be called if pinchToZoomn = true
// Returns a CGFloat of the current zoom level
}
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection) {
// Called if the user denied access to the Camera or Microphone
// Will only be called if promptToAppPrivacySettings = false
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
// Called when user switches between cameras
// Returns current camera selection
}
```
@ -225,9 +225,9 @@ Video quality can be set by the **videoQuality** property of SwiftyCamViewContro
| VideoQuality | AVCaptureSessionPreset
| ------------------------------------- | ---------------------
| `.high` | **AVCapturePresetHigh**
| `.medium` | **AVCapturePresetMedium**
| `.low` | **AVCapturePresetLow**
| `.high` | **AVCapturePresetHigh**
| `.medium` | **AVCapturePresetMedium**
| `.low` | **AVCapturePresetLow**
| `.resolution352x288` | **AVCaptureSessionPreset352x288**
| `.resolution640x480` | **AVCaptureSessionPreset640x480**
| `.resolution1280x720` | **AVCaptureSessionPreset1280x720**
@ -241,10 +241,10 @@ The default value is **.high**. For use with the front-facing camera, **.high**
### Maximum Video Duration
If using a SwiftyCamButton, you can set a maximum video duration for the length of video. The video recording will me automatically stopped once the time limit has been reached and the delegate method `SwiftyCamDidFinishRecordingVideo` will be called. To set this value, simply change the `kMaximumVideoDuration` value:
If using a SwiftyCamButton, you can set a maximum video duration for the length of video. The video recording will me automatically stopped once the time limit has been reached and the delegate method `SwiftyCamDidFinishRecordingVideo` will be called. To set this value, simply change the `maximumVideoDuration` value:
```swift
kMaximumVideoDuration = 10.0
maximumVideoDuration = 10.0
```
A value of **0.0** will allow for unlimited video recording via the SwiftyCamButton. The default value is **0.0**.
@ -287,13 +287,7 @@ lowLightBoost = false
## Privacy
When a user firsts launch SwiftyCamViewController, they will be prompted for permission for access to the cameras and microphones. By default, if a user declines access to the hardware, SwiftyCam will provide a prompt to the App privacy settings inside the iOS settings application. If you wish to change this behaviour, the `promptToAppPrivacySettings*`property can be modified:
```swift
promptToAppPrivacySettings = false
```
Instead of prompting the user to the settings application, the delegate method `SwiftyCamDidFailCameraPermissionSettings` will be called and will have to be manually handled.
When a user firsts launch SwiftyCamViewController, they will be prompted for permission for access to the cameras and microphones. By default, if a user declines access to the hardware, SwiftyCam will provide a prompt to the App privacy settings inside the iOS settings application.
## Miscellaneous

View file

@ -95,7 +95,7 @@ open class SwiftyCamViewController: UIViewController {
/// Maxiumum video duration if SwiftyCamButton is used
public var kMaximumVideoDuration : Double = 0.0
public var maximumVideoDuration : Double = 0.0
/// Video capture quality
@ -119,10 +119,6 @@ open class SwiftyCamViewController: UIViewController {
public var lowLightBoost = true
/// Sets whether SwiftyCam will prompt a user to the App Settings Screen if Camera or Microphone access is not authorized
public var promptToAppPrivacySettings = true
/// Set whether SwiftyCam should allow background audio from other applications
public var allowBackgroundAudio = true
@ -368,12 +364,8 @@ open class SwiftyCamViewController: UIViewController {
if currentCamera == .front && flashEnabled == true {
flashView = UIView(frame: view.frame)
flashView?.backgroundColor = UIColor.white
flashView?.alpha = 0.0
flashView?.alpha = 0.85
previewLayer.addSubview(flashView!)
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
self.flashView?.alpha = 0.85
}, completion: nil)
}
let videoPreviewLayerOrientation = previewLayer!.videoPreviewLayer.connection.videoOrientation
@ -400,7 +392,7 @@ open class SwiftyCamViewController: UIViewController {
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
self.isVideoRecording = true
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
self.cameraDelegate?.swiftyCam(self, didBeginRecordingVideo: self.currentCamera)
}
}
else {
@ -419,7 +411,7 @@ open class SwiftyCamViewController: UIViewController {
*/
public func endVideoRecording() {
public func stopVideoRecording() {
if self.movieFileOutput?.isRecording == true {
self.isVideoRecording = false
movieFileOutput!.stopRecording()
@ -433,7 +425,7 @@ open class SwiftyCamViewController: UIViewController {
})
}
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
self.cameraDelegate?.swiftyCam(self, didFinishRecordingVideo: self.currentCamera)
}
}
}
@ -472,7 +464,7 @@ open class SwiftyCamViewController: UIViewController {
self.addInputs()
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidSwitchCameras(camera: self.currentCamera)
self.cameraDelegate?.swiftyCam(self, didSwitchCameras: self.currentCamera)
}
self.session.startRunning()
@ -669,7 +661,7 @@ open class SwiftyCamViewController: UIViewController {
// Call delegate and return new image
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidTakePhoto(image)
self.cameraDelegate?.swiftyCam(self, didTake: image)
}
completionHandler(true)
} else {
@ -684,16 +676,6 @@ open class SwiftyCamViewController: UIViewController {
/// Handle Denied App Privacy Settings
fileprivate func promptToAppSettings() {
guard promptToAppPrivacySettings == true else {
// Do not prompt user
// Call delegate function SwiftyCamDidFailCameraPermissionSettings()
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidFailCameraPermissionSettings()
}
return
}
// prompt User with UIAlertView
DispatchQueue.main.async(execute: { [unowned self] in
@ -836,7 +818,7 @@ extension SwiftyCamViewController : SwiftyCamButtonDelegate {
/// Sets the maximum duration of the SwiftyCamButton
public func setMaxiumVideoDuration() -> Double {
return kMaximumVideoDuration
return maximumVideoDuration
}
/// Set UITapGesture to take photo
@ -855,13 +837,13 @@ extension SwiftyCamViewController : SwiftyCamButtonDelegate {
public func buttonDidEndLongPress() {
endVideoRecording()
stopVideoRecording()
}
/// Called if maximum duration is reached
public func longPressDidReachMaximumDuration() {
endVideoRecording()
stopVideoRecording()
}
}
@ -884,7 +866,7 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
} else {
//Call delegate function with the URL of the outputfile
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidFinishProcessingVideoAt(outputFileURL)
self.cameraDelegate?.swiftyCam(self, didFinishProcessVideoAt: outputFileURL)
}
}
}
@ -911,7 +893,7 @@ extension SwiftyCamViewController {
// Call Delegate function with current zoom scale
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidChangeZoomLevel(zoomLevel: self.zoomScale)
self.cameraDelegate?.swiftyCam(self, didChangeZoomLevel: self.zoomScale)
}
captureDevice?.unlockForConfiguration()
@ -949,7 +931,7 @@ extension SwiftyCamViewController {
//Call delegate function and pass in the location of the touch
DispatchQueue.main.async {
self.cameraDelegate?.SwiftyCamDidFocusAtPoint(focusPoint: tapPoint)
self.cameraDelegate?.swiftyCam(self, didFocusAtPoint: tapPoint)
}
}
catch {

View file

@ -23,97 +23,103 @@ import UIKit
public protocol SwiftyCamViewControllerDelegate {
/**
SwiftyCamViewControllerDelegate function called when the takePhoto() function is called
SwiftyCamViewControllerDelegate function called when the takePhoto() function is called.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter photo: UIImage captured from the current session
*/
func SwiftyCamDidTakePhoto(_ photo:UIImage)
/// SwiftyCamViewControllerDelegate function called when SwiftyCamViewController begins recording video
func SwiftyCamDidBeginRecordingVideo()
/// SwiftyCamViewControllerDelegate function called when SwiftyCamViewController finishes recording video
func SwiftyCamDidFinishRecordingVideo()
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage)
/**
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController is done processing video
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController begins recording video.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter camera: Current camera orientation
*/
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection)
/**
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController finishes recording video.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter camera: Current camera orientation
*/
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection)
/**
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController is done processing video.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter url: URL location of video in temporary directory
*/
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL)
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL)
/**
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController switches between front or rear camera
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController switches between front or rear camera.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter camera: Current camera selection
*/
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection)
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection)
/**
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController view is tapped and begins focusing at that point
SwiftyCamViewControllerDelegate function called when SwiftyCamViewController view is tapped and begins focusing at that point.
- Parameter focusPoint: Location in view where camera focused
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter point: Location in view where camera focused
*/
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint)
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint)
/**
SwiftyCamViewControllerDelegate function called when when SwiftyCamViewController view changes zoom level
- Parameter zoomLevel: Current zoom level
SwiftyCamViewControllerDelegate function called when when SwiftyCamViewController view changes zoom level.
- Parameter swiftyCam: Current SwiftyCamViewController session
- Parameter zoom: Current zoom level
*/
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat)
/// SwiftyCamViewControllerDelegate function called if app permissions are denied for either Camera or Microphone
func SwiftyCamDidFailCameraPermissionSettings()
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat)
}
public extension SwiftyCamViewControllerDelegate {
func SwiftyCamDidTakePhoto(_ photo:UIImage) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage) {
// Optional
}
func SwiftyCamDidBeginRecordingVideo() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
// Optional
}
func SwiftyCamDidFinishRecordingVideo() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
// Optional
}
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL) {
// Optional
}
func SwiftyCamDidSwitchCameras(camera: SwiftyCamViewController.CameraSelection) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
// Optional
}
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint) {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint) {
// Optional
}
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat) {
// Optional
}
func SwiftyCamDidFailCameraPermissionSettings() {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
// Optional
}
}