diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Contents.json index da4a164..73c0059 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Contents.json +++ b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json deleted file mode 100644 index a8d38c3..0000000 --- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "flash@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "flash@3x.png", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png deleted file mode 100644 index 409bc69..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png deleted file mode 100644 index 7cbe495..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json deleted file mode 100644 index 193bcc2..0000000 --- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "flashOutline@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "flashOutline@3x.png", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png deleted file mode 100644 index a587b1a..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png deleted file mode 100644 index c07b935..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/Contents.json deleted file mode 100644 index 6cd836f..0000000 --- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "flashauto@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "filename" : "flashauto@3x.png", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@2x.png deleted file mode 100644 index 8d15610..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@2x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@3x.png deleted file mode 100644 index cc7666e..0000000 Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@3x.png and /dev/null differ diff --git a/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard b/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard index 0f4d088..a39fcda 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard +++ b/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard @@ -1,11 +1,8 @@ - - - - + + - - + @@ -36,40 +33,26 @@ - - - - + - diff --git a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift index 7f8c8da..d387c02 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift @@ -21,16 +21,13 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate { @IBOutlet weak var captureButton : SwiftyRecordButton! @IBOutlet weak var flipCameraButton : UIButton! - @IBOutlet weak var flashButton : UIButton! - + override func viewDidLoad() { super.viewDidLoad() shouldPrompToAppSettings = true cameraDelegate = self allowAutoRotate = true audioEnabled = true - flashMode = .auto - flashButton.setImage(#imageLiteral(resourceName: "flashauto"), for: UIControl.State()) captureButton.buttonEnabled = false } @@ -100,11 +97,6 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate { @IBAction func cameraSwitchTapped(_ sender: Any) { switchCamera() } - - @IBAction func toggleFlashTapped(_ sender: Any) { - //flashEnabled = !flashEnabled - toggleFlashAnimation() - } } @@ -113,14 +105,12 @@ extension ViewController { fileprivate func hideButtons() { UIView.animate(withDuration: 0.25) { - self.flashButton.alpha = 0.0 self.flipCameraButton.alpha = 0.0 } } fileprivate func showButtons() { UIView.animate(withDuration: 0.25) { - self.flashButton.alpha = 1.0 self.flipCameraButton.alpha = 1.0 } } @@ -143,19 +133,4 @@ extension ViewController { } } } - - fileprivate func toggleFlashAnimation() { - //flashEnabled = !flashEnabled - if flashMode == .auto{ - flashMode = .on - flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControl.State()) - }else if flashMode == .on{ - flashMode = .off - flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControl.State()) - }else if flashMode == .off{ - flashMode = .auto - flashButton.setImage(#imageLiteral(resourceName: "flashauto"), for: UIControl.State()) - } - } } - diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index 0d5416e..1e13029 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -43,28 +43,6 @@ open class SwiftyCamViewController: UIViewController { } } - public enum FlashMode{ - //Return the equivalent AVCaptureDevice.FlashMode - var AVFlashMode: AVCaptureDevice.FlashMode { - switch self { - case .on: - return .on - case .off: - return .off - case .auto: - return .auto - } - } - //Flash mode is set to auto - case auto - - //Flash mode is set to on - case on - - //Flash mode is set to off - case off - } - /// Enumeration for video quality of the capture session. Corresponds to a AVCaptureSessionPreset @@ -126,9 +104,6 @@ open class SwiftyCamViewController: UIViewController { public var videoQuality : VideoQuality = .high - // Flash Mode - public var flashMode:FlashMode = .off - /// Sets whether Pinch to Zoom is enabled for the capture session public var pinchToZoom = true @@ -226,10 +201,6 @@ 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 @@ -254,10 +225,6 @@ open class SwiftyCamViewController: UIViewController { fileprivate var previewLayer : PreviewView! - /// UIView for front facing flash - - fileprivate var flashView : UIView? - /// Pan Translation fileprivate var previousPanTranslation : CGFloat = 0.0 @@ -412,9 +379,6 @@ open class SwiftyCamViewController: UIViewController { self.isSessionRunning = false } - //Disble flash if it is currently enabled - disableFlash() - // Unsubscribe from device rotation notifications rotationCoordinator = nil } @@ -439,17 +403,6 @@ open class SwiftyCamViewController: UIViewController { return } - if currentCamera == .rear && flashMode == .on { - enableFlash() - } - - if currentCamera == .front && flashMode == .on { - flashView = UIView(frame: view.frame) - flashView?.backgroundColor = UIColor.white - flashView?.alpha = 0.85 - previewLayer.addSubview(flashView!) - } - sessionQueue.async { [unowned self] in if !movieFileOutput.isRecording { if UIDevice.current.isMultitaskingSupported { @@ -497,15 +450,7 @@ open class SwiftyCamViewController: UIViewController { if self.isVideoRecording == true { self.isVideoRecording = false movieFileOutput!.stopRecording() - disableFlash() - if currentCamera == .front && flashMode == .on && flashView != nil { - UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: { - self.flashView?.alpha = 0.0 - }, completion: { (_) in - self.flashView?.removeFromSuperview() - }) - } DispatchQueue.main.async { self.cameraDelegate?.swiftyCam(self, didFinishRecordingVideo: self.currentCamera) } @@ -556,9 +501,6 @@ open class SwiftyCamViewController: UIViewController { self.session.startRunning() } - - // If flash is enabled, disable it as the torch is needed for front facing camera - disableFlash() } // MARK: Private Functions @@ -770,53 +712,6 @@ open class SwiftyCamViewController: UIViewController { ?? AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: position) } - /// Enable flash - - fileprivate func enableFlash() { - if self.isCameraTorchOn == false { - toggleFlash() - } - } - - /// Disable flash - - fileprivate func disableFlash() { - if self.isCameraTorchOn == true { - toggleFlash() - } - } - - /// Toggles between enabling and disabling flash - - fileprivate func toggleFlash() { - guard self.currentCamera == .rear else { - // Flash is not supported for front facing camera - return - } - - let device = AVCaptureDevice.default(for: AVMediaType.video) - // Check if device has a flash - if (device?.hasTorch)! { - do { - try device?.lockForConfiguration() - if (device?.torchMode == AVCaptureDevice.TorchMode.on) { - device?.torchMode = AVCaptureDevice.TorchMode.off - self.isCameraTorchOn = false - } else { - do { - try device?.setTorchModeOn(level: 1.0) - self.isCameraTorchOn = true - } catch { - print("[SwiftyCam]: \(error)") - } - } - device?.unlockForConfiguration() - } catch { - print("[SwiftyCam]: \(error)") - } - } - } - /// Sets whether SwiftyCam should enable background audio from other applications or sources fileprivate func setBackgroundAudioPreference() {