mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Added front facing flash support
This commit is contained in:
parent
72b852fa4b
commit
29448b7c5c
5 changed files with 65 additions and 24 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# CHANGELOG
|
||||
|
||||
## Version 1.3.0
|
||||
- Added support for front facing flash
|
||||
- Added support for front facing Retina Flash (on supported models)
|
||||
- Added support for front facing torch mode for video capture
|
||||
|
||||
## Version 1.2.3
|
||||
- Added support for Swift Package Manager
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
super.viewDidLoad()
|
||||
cameraDelegate = self
|
||||
kMaximumVideoDuration = 10.0
|
||||
tapToFocus = true
|
||||
pinchToZoom = true
|
||||
lowLightBoost = true
|
||||
}
|
||||
|
||||
override var prefersStatusBarHidden: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
|
|
|
|||
17
README.md
17
README.md
|
|
@ -23,10 +23,11 @@ Configuring a Camera View Controller in AVFoundation can be tedious and time con
|
|||
:movie_camera: | Video capture
|
||||
:chart_with_upwards_trend: | Manual image quality settings
|
||||
:tada: | Front and rear camera support
|
||||
:flashlight: | Torch/flash settings
|
||||
:flashlight: | Front and rear flash
|
||||
:sunny: | Retina flash support
|
||||
:mag_right: | Supports manual zoom
|
||||
:lock: | Supports manual focus
|
||||
:last_quarter_moon_with_face: | low light setting
|
||||
:last_quarter_moon_with_face: | Low light setting
|
||||
|
||||
|
||||
## Requirements
|
||||
|
|
@ -141,8 +142,18 @@ and in your viewDidLoad, assign the cameraDelegate to self:
|
|||
The flash(torch) can be enabled by changing the **flashEnabled** property:
|
||||
|
||||
flashEnabled = true
|
||||
|
||||
Flash is now supported for front and rear facing cameras.
|
||||
|
||||
The flash will only be enabled if the current camera is the rear camera. For photos, the camera will flash much like the stock iOS camera. For video, the torch(flash) will enable for the duration of the video capture.
|
||||
### Rear Camera
|
||||
|
||||
For photos, the camera will flash much like the stock iOS camera. For video, the torch(flash) will enable for the duration of the video capture.
|
||||
|
||||
### Front Camera
|
||||
|
||||
For models that support [Retina Flash](https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html#//apple_ref/doc/uid/TP40013599-CH107-SW7), the front camera will use the default flash for image capture. If Retina Flash is not supported, a faux Retina Flash is used similar to Snapchat.
|
||||
|
||||
For front facing videos, a white, 85% opaque view will be placed over the video feed for the duration of the video capture.
|
||||
|
||||
## Switching Camera
|
||||
|
||||
|
|
|
|||
|
|
@ -126,10 +126,6 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
// MARK: Public Get-only Variable Declarations
|
||||
|
||||
/// Returns true if the torch (flash) is currently enabled
|
||||
|
||||
private(set) public var isCameraFlashOn = false
|
||||
|
||||
/// Returns true if video is currently being recorded
|
||||
|
||||
private(set) public var isVideRecording = false
|
||||
|
|
@ -162,6 +158,10 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
fileprivate var beginZoomScale = CGFloat(1.0)
|
||||
|
||||
/// Returns true if the torch (flash) is currently enabled
|
||||
|
||||
fileprivate var isCameraTorchOn = false
|
||||
|
||||
/// Variable to store result of capture session setup
|
||||
|
||||
fileprivate var setupResult = SessionSetupResult.success
|
||||
|
|
@ -190,8 +190,13 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
fileprivate var previewLayer : PreviewView!
|
||||
|
||||
/// UIView for front facing flash
|
||||
|
||||
fileprivate var flashView : UIView?
|
||||
|
||||
/// Disable view autorotation for forced portrait recorindg
|
||||
|
||||
|
||||
override open var shouldAutorotate: Bool {
|
||||
return false
|
||||
}
|
||||
|
|
@ -306,20 +311,20 @@ open class SwiftyCamViewController: UIViewController {
|
|||
capturePhotoAsyncronously(completionHandler: { (_) in })
|
||||
|
||||
} else if device.hasFlash == false && flashEnabled == true && currentCamera == .front {
|
||||
let flashView = UIView(frame: view.frame)
|
||||
flashView.alpha = 0.0
|
||||
flashView.backgroundColor = UIColor.white
|
||||
view.addSubview(flashView)
|
||||
flashView = UIView(frame: view.frame)
|
||||
flashView?.alpha = 0.0
|
||||
flashView?.backgroundColor = UIColor.white
|
||||
previewLayer.addSubview(flashView!)
|
||||
|
||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||
flashView.alpha = 1.0
|
||||
self.flashView?.alpha = 1.0
|
||||
|
||||
}, completion: { (_) in
|
||||
self.capturePhotoAsyncronously(completionHandler: { (success) in
|
||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||
flashView.alpha = 0.0
|
||||
self.flashView?.alpha = 0.0
|
||||
}, completion: { (_) in
|
||||
flashView.removeFromSuperview()
|
||||
self.flashView?.removeFromSuperview()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -348,6 +353,17 @@ open class SwiftyCamViewController: UIViewController {
|
|||
enableFlash()
|
||||
}
|
||||
|
||||
if currentCamera == .front && flashEnabled == true {
|
||||
flashView = UIView(frame: view.frame)
|
||||
flashView?.backgroundColor = UIColor.white
|
||||
flashView?.alpha = 0.0
|
||||
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
|
||||
|
||||
sessionQueue.async { [unowned self] in
|
||||
|
|
@ -394,6 +410,14 @@ open class SwiftyCamViewController: UIViewController {
|
|||
self.isVideRecording = false
|
||||
movieFileOutput!.stopRecording()
|
||||
disableFlash()
|
||||
|
||||
if currentCamera == .front && flashEnabled == true && flashView != nil {
|
||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||
self.flashView?.alpha = 0.0
|
||||
}, completion: { (_) in
|
||||
self.flashView?.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
|
||||
}
|
||||
}
|
||||
|
|
@ -438,7 +462,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
self.session.startRunning()
|
||||
}
|
||||
|
||||
// If flash is enabled, disable it as flash is not supported or needed for front facing camera
|
||||
// If flash is enabled, disable it as the torch is needed for front facing camera
|
||||
disableFlash()
|
||||
}
|
||||
|
||||
|
|
@ -783,7 +807,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
/// Enable flash
|
||||
|
||||
fileprivate func enableFlash() {
|
||||
if self.isCameraFlashOn == false {
|
||||
if self.isCameraTorchOn == false {
|
||||
toggleFlash()
|
||||
}
|
||||
}
|
||||
|
|
@ -791,7 +815,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
/// Disable flash
|
||||
|
||||
fileprivate func disableFlash() {
|
||||
if self.isCameraFlashOn == true {
|
||||
if self.isCameraTorchOn == true {
|
||||
toggleFlash()
|
||||
}
|
||||
}
|
||||
|
|
@ -811,11 +835,11 @@ open class SwiftyCamViewController: UIViewController {
|
|||
try device?.lockForConfiguration()
|
||||
if (device?.torchMode == AVCaptureTorchMode.on) {
|
||||
device?.torchMode = AVCaptureTorchMode.off
|
||||
self.isCameraFlashOn = false
|
||||
self.isCameraTorchOn = false
|
||||
} else {
|
||||
do {
|
||||
try device?.setTorchModeOnWithLevel(1.0)
|
||||
self.isCameraFlashOn = true
|
||||
self.isCameraTorchOn = true
|
||||
} catch {
|
||||
print("[SwiftyCam]: \(error)")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftyCam'
|
||||
s.version = '1.2.3'
|
||||
s.summary = 'A Simple, Snapchat-style camera Framework written in Swift'
|
||||
s.version = '1.3.0'
|
||||
s.summary = 'A Simple, Snapchat inspired camera Framework written in Swift'
|
||||
s.ios.deployment_target = '8.0'
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue