diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@2x.png
deleted file mode 100644
index b98c6d8..0000000
Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@2x.png and /dev/null differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@3x.png
deleted file mode 100644
index 08466a4..0000000
Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Camera@3x.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 f7f6b25..0000000
Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Flash.imageset/Flash@3x.png and /dev/null differ
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 3429e90..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/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json
similarity index 89%
rename from DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Flash.imageset/Contents.json
rename to DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json
index b602c3e..a8d38c3 100644
--- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Flash.imageset/Contents.json
+++ b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/Contents.json
@@ -11,7 +11,7 @@
},
{
"idiom" : "universal",
- "filename" : "Flash@3x.png",
+ "filename" : "flash@3x.png",
"scale" : "3x"
}
],
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png
new file mode 100644
index 0000000..409bc69
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png
new file mode 100644
index 0000000..7cbe495
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json
similarity index 76%
rename from DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Contents.json
rename to DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json
index e9bc18f..193bcc2 100644
--- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/Camera.imageset/Contents.json
+++ b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/Contents.json
@@ -6,12 +6,12 @@
},
{
"idiom" : "universal",
- "filename" : "Camera@2x.png",
+ "filename" : "flashOutline@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
- "filename" : "Camera@3x.png",
+ "filename" : "flashOutline@3x.png",
"scale" : "3x"
}
],
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png
new file mode 100644
index 0000000..a587b1a
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png
new file mode 100644
index 0000000..c07b935
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@2x.png
new file mode 100644
index 0000000..11908e0
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@2x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@3x.png
new file mode 100644
index 0000000..93b81a2
Binary files /dev/null and b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@3x.png differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/Contents.json b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/Contents.json
index 6d041ed..7b048cf 100644
--- a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/Contents.json
+++ b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/Contents.json
@@ -6,12 +6,12 @@
},
{
"idiom" : "universal",
- "filename" : "flipcamera@2x.png",
+ "filename" : "CameraSwitch@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
- "filename" : "flipCamera@3x.png",
+ "filename" : "CameraSwitch@3x.png",
"scale" : "3x"
}
],
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipCamera@3x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipCamera@3x.png
deleted file mode 100644
index a3cfc93..0000000
Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipCamera@3x.png and /dev/null differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipcamera@2x.png b/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipcamera@2x.png
deleted file mode 100644
index 06f2ae0..0000000
Binary files a/DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/flipcamera@2x.png and /dev/null differ
diff --git a/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard b/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard
index b199a4c..f707882 100644
--- a/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard
+++ b/DemoSwiftyCam/DemoSwiftyCam/Base.lproj/Main.storyboard
@@ -5,7 +5,6 @@
-
@@ -20,41 +19,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift
index 78ec1a1..2a9c58c 100644
--- a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift
+++ b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift
@@ -18,14 +18,16 @@ import UIKit
class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
- @IBOutlet weak var flipCameraButton: UIButton!
- @IBOutlet weak var toggleFlashButton: UIButton!
+ var flipCameraButton: UIButton!
+ var flashButton: UIButton!
var captureButton: SwiftyRecordButton!
override func viewDidLoad() {
super.viewDidLoad()
cameraDelegate = self
kMaximumVideoDuration = 10.0
+ addButtons()
+
}
override var prefersStatusBarHidden: Bool {
@@ -34,13 +36,6 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
-
- captureButton = SwiftyRecordButton(frame: CGRect(x: view.frame.midX - 37.5, y: view.frame.height - 100.0, width: 75.0, height: 75.0))
- self.view.addSubview(captureButton)
- captureButton.delegate = self
- self.view.bringSubview(toFront: captureButton)
- self.view.bringSubview(toFront: flipCameraButton)
- self.view.bringSubview(toFront: toggleFlashButton)
}
func SwiftyCamDidTakePhoto(_ photo: UIImage) {
@@ -49,10 +44,18 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
func SwiftyCamDidBeginRecordingVideo() {
print("Did Begin Recording")
+ UIView.animate(withDuration: 0.25, animations: {
+ self.flashButton.alpha = 0.0
+ self.flipCameraButton.alpha = 0.0
+ })
}
func SwiftyCamDidFinishRecordingVideo() {
print("Did finish Recording")
+ UIView.animate(withDuration: 0.25, animations: {
+ self.flashButton.alpha = 1.0
+ self.flipCameraButton.alpha = 1.0
+ })
}
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
@@ -71,12 +74,37 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
print(camera)
}
- @IBAction func cameraSwitchAction(_ sender: Any) {
+ @objc private func cameraSwitchAction(_ sender: Any) {
switchCamera()
}
- @IBAction func toggleFlashAction(_ sender: Any) {
+ @objc private func toggleFlashAction(_ sender: Any) {
flashEnabled = !flashEnabled
+
+ if flashEnabled == true {
+ flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState())
+ } else {
+ flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
+ }
+ }
+
+ private func addButtons() {
+ captureButton = SwiftyRecordButton(frame: CGRect(x: view.frame.midX - 37.5, y: view.frame.height - 100.0, width: 75.0, height: 75.0))
+ self.view.addSubview(captureButton)
+ //self.view.bringSubview(toFront: captureButton)
+ captureButton.delegate = self
+
+ flipCameraButton = UIButton(frame: CGRect(x: view.frame.width / 4 - 15.0, y: view.frame.height - 74.0, width: 30.0, height: 23.0))
+ flipCameraButton.setImage(#imageLiteral(resourceName: "flipCamera"), for: UIControlState())
+ flipCameraButton.addTarget(self, action: #selector(cameraSwitchAction(_:)), for: .touchUpInside)
+ self.view.addSubview(flipCameraButton)
+ //self.view.bringSubview(toFront: flipCameraButton)
+
+ flashButton = UIButton(frame: CGRect(x: view.frame.width * 3 / 4 - 9.0, y: view.frame.height - 77.5, width: 18.0, height: 30.0))
+ flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
+ flashButton.addTarget(self, action: #selector(toggleFlashAction(_:)), for: .touchUpInside)
+ self.view.addSubview(flashButton)
+ // self.view.bringSubview(toFront: flashButton)
}
}
diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift
index b43b7ec..2302983 100644
--- a/Source/SwiftyCamViewController.swift
+++ b/Source/SwiftyCamViewController.swift
@@ -395,7 +395,9 @@ open class SwiftyCamViewController: UIViewController {
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
self.isVideoRecording = true
- self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
+ }
}
else {
movieFileOutput.stopRecording()
@@ -426,7 +428,9 @@ open class SwiftyCamViewController: UIViewController {
self.flashView?.removeFromSuperview()
})
}
- self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
+ }
}
}
@@ -463,7 +467,10 @@ open class SwiftyCamViewController: UIViewController {
}
self.addInputs()
- self.cameraDelegate?.SwiftyCamDidSwitchCameras(camera: self.currentCamera)
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidSwitchCameras(camera: self.currentCamera)
+ }
+
self.session.startRunning()
}
@@ -496,7 +503,10 @@ open class SwiftyCamViewController: UIViewController {
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
device.unlockForConfiguration()
//Call delegate function and pass in the location of the touch
- self.cameraDelegate?.SwiftyCamDidFocusAtPoint(focusPoint: touchPoint.location(in: previewLayer))
+
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidFocusAtPoint(focusPoint: touchPoint.location(in: self.previewLayer))
+ }
}
catch {
// just ignore
@@ -691,7 +701,9 @@ open class SwiftyCamViewController: UIViewController {
let image = self.processPhoto(imageData!)
// Call delegate and return new image
- self.cameraDelegate?.SwiftyCamDidTakePhoto(image)
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidTakePhoto(image)
+ }
completionHandler(true)
} else {
completionHandler(false)
@@ -718,7 +730,9 @@ open class SwiftyCamViewController: UIViewController {
captureDevice?.videoZoomFactor = zoomScale
// Call Delegate function with current zoom scale
- self.cameraDelegate?.SwiftyCamDidChangeZoomLevel(zoomLevel: zoomScale)
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidChangeZoomLevel(zoomLevel: self.zoomScale)
+ }
captureDevice?.unlockForConfiguration()
@@ -745,8 +759,11 @@ open class SwiftyCamViewController: UIViewController {
fileprivate func promptToAppSettings() {
guard promptToAppPrivacySettings == true else {
// Do not prompt user
- // Ca// delegate function SwiftyCamDidFailCameraPermissionSettings()
- self.cameraDelegate?.SwiftyCamDidFailCameraPermissionSettings()
+ // Call delegate function SwiftyCamDidFailCameraPermissionSettings()
+
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidFailCameraPermissionSettings()
+ }
return
}
@@ -939,7 +956,9 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
print("[SwiftyCam]: Movie file finishing error: \(error)")
} else {
//Call delegate function with the URL of the outputfile
- self.cameraDelegate?.SwiftyCamDidFinishProcessingVideoAt(outputFileURL)
+ DispatchQueue.main.async {
+ self.cameraDelegate?.SwiftyCamDidFinishProcessingVideoAt(outputFileURL)
+ }
}
}
}