Created new demo UI and fixed issue with delegate calls not on main queue
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 2 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
|
@ -11,7 +11,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"filename" : "Flash@3x.png",
|
"filename" : "flash@3x.png",
|
||||||
"scale" : "3x"
|
"scale" : "3x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 935 B |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flash.imageset/flash@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
|
|
@ -6,12 +6,12 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"filename" : "Camera@2x.png",
|
"filename" : "flashOutline@2x.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"filename" : "Camera@3x.png",
|
"filename" : "flashOutline@3x.png",
|
||||||
"scale" : "3x"
|
"scale" : "3x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashOutline.imageset/flashOutline@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flipCamera.imageset/CameraSwitch@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 2 KiB |
|
|
@ -6,12 +6,12 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"filename" : "flipcamera@2x.png",
|
"filename" : "CameraSwitch@2x.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"filename" : "flipCamera@3x.png",
|
"filename" : "CameraSwitch@3x.png",
|
||||||
"scale" : "3x"
|
"scale" : "3x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
|
@ -5,7 +5,6 @@
|
||||||
</device>
|
</device>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
|
||||||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
|
|
||||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<scenes>
|
<scenes>
|
||||||
|
|
@ -20,41 +19,11 @@
|
||||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SH4-0K-8ra">
|
|
||||||
<rect key="frame" x="325" y="30" width="30" height="22"/>
|
|
||||||
<state key="normal" image="Flash"/>
|
|
||||||
<connections>
|
|
||||||
<action selector="toggleFlashAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="j1T-ak-teR"/>
|
|
||||||
</connections>
|
|
||||||
</button>
|
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Bb3-ix-Jd1">
|
|
||||||
<rect key="frame" x="20" y="28" width="30" height="26"/>
|
|
||||||
<state key="normal" image="flipCamera"/>
|
|
||||||
<connections>
|
|
||||||
<action selector="cameraSwitchAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="a9E-90-SZM"/>
|
|
||||||
</connections>
|
|
||||||
</button>
|
|
||||||
</subviews>
|
|
||||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<constraints>
|
|
||||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="8" symbolic="YES" id="2Fx-Ut-jDO"/>
|
|
||||||
<constraint firstAttribute="trailingMargin" secondItem="SH4-0K-8ra" secondAttribute="trailing" constant="4" id="AiE-Y6-Sxj"/>
|
|
||||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="centerY" secondItem="SH4-0K-8ra" secondAttribute="centerY" id="Cnv-VO-rR3"/>
|
|
||||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="4" id="yuS-xl-hcP"/>
|
|
||||||
</constraints>
|
|
||||||
</view>
|
</view>
|
||||||
<connections>
|
|
||||||
<outlet property="flipCameraButton" destination="Bb3-ix-Jd1" id="Q9m-ib-9iQ"/>
|
|
||||||
<outlet property="toggleFlashButton" destination="SH4-0K-8ra" id="BSt-X8-4Do"/>
|
|
||||||
</connections>
|
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
<resources>
|
|
||||||
<image name="Flash" width="30" height="19"/>
|
|
||||||
<image name="flipCamera" width="30" height="26"/>
|
|
||||||
</resources>
|
|
||||||
</document>
|
</document>
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,16 @@ import UIKit
|
||||||
|
|
||||||
class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var flipCameraButton: UIButton!
|
var flipCameraButton: UIButton!
|
||||||
@IBOutlet weak var toggleFlashButton: UIButton!
|
var flashButton: UIButton!
|
||||||
var captureButton: SwiftyRecordButton!
|
var captureButton: SwiftyRecordButton!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
cameraDelegate = self
|
cameraDelegate = self
|
||||||
kMaximumVideoDuration = 10.0
|
kMaximumVideoDuration = 10.0
|
||||||
|
addButtons()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override var prefersStatusBarHidden: Bool {
|
override var prefersStatusBarHidden: Bool {
|
||||||
|
|
@ -34,13 +36,6 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
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) {
|
func SwiftyCamDidTakePhoto(_ photo: UIImage) {
|
||||||
|
|
@ -49,10 +44,18 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
|
|
||||||
func SwiftyCamDidBeginRecordingVideo() {
|
func SwiftyCamDidBeginRecordingVideo() {
|
||||||
print("Did Begin Recording")
|
print("Did Begin Recording")
|
||||||
|
UIView.animate(withDuration: 0.25, animations: {
|
||||||
|
self.flashButton.alpha = 0.0
|
||||||
|
self.flipCameraButton.alpha = 0.0
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SwiftyCamDidFinishRecordingVideo() {
|
func SwiftyCamDidFinishRecordingVideo() {
|
||||||
print("Did finish Recording")
|
print("Did finish Recording")
|
||||||
|
UIView.animate(withDuration: 0.25, animations: {
|
||||||
|
self.flashButton.alpha = 1.0
|
||||||
|
self.flipCameraButton.alpha = 1.0
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
|
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
|
||||||
|
|
@ -71,12 +74,37 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
print(camera)
|
print(camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func cameraSwitchAction(_ sender: Any) {
|
@objc private func cameraSwitchAction(_ sender: Any) {
|
||||||
switchCamera()
|
switchCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func toggleFlashAction(_ sender: Any) {
|
@objc private func toggleFlashAction(_ sender: Any) {
|
||||||
flashEnabled = !flashEnabled
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
|
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
|
||||||
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
|
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
|
||||||
self.isVideoRecording = true
|
self.isVideoRecording = true
|
||||||
self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
movieFileOutput.stopRecording()
|
movieFileOutput.stopRecording()
|
||||||
|
|
@ -426,7 +428,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
self.flashView?.removeFromSuperview()
|
self.flashView?.removeFromSuperview()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidFinishRecordingVideo()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -463,7 +467,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addInputs()
|
self.addInputs()
|
||||||
self.cameraDelegate?.SwiftyCamDidSwitchCameras(camera: self.currentCamera)
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidSwitchCameras(camera: self.currentCamera)
|
||||||
|
}
|
||||||
|
|
||||||
self.session.startRunning()
|
self.session.startRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,7 +503,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
|
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
|
||||||
device.unlockForConfiguration()
|
device.unlockForConfiguration()
|
||||||
//Call delegate function and pass in the location of the touch
|
//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 {
|
catch {
|
||||||
// just ignore
|
// just ignore
|
||||||
|
|
@ -691,7 +701,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
let image = self.processPhoto(imageData!)
|
let image = self.processPhoto(imageData!)
|
||||||
|
|
||||||
// Call delegate and return new image
|
// Call delegate and return new image
|
||||||
self.cameraDelegate?.SwiftyCamDidTakePhoto(image)
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidTakePhoto(image)
|
||||||
|
}
|
||||||
completionHandler(true)
|
completionHandler(true)
|
||||||
} else {
|
} else {
|
||||||
completionHandler(false)
|
completionHandler(false)
|
||||||
|
|
@ -718,7 +730,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
captureDevice?.videoZoomFactor = zoomScale
|
captureDevice?.videoZoomFactor = zoomScale
|
||||||
|
|
||||||
// Call Delegate function with current zoom scale
|
// Call Delegate function with current zoom scale
|
||||||
self.cameraDelegate?.SwiftyCamDidChangeZoomLevel(zoomLevel: zoomScale)
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidChangeZoomLevel(zoomLevel: self.zoomScale)
|
||||||
|
}
|
||||||
|
|
||||||
captureDevice?.unlockForConfiguration()
|
captureDevice?.unlockForConfiguration()
|
||||||
|
|
||||||
|
|
@ -745,8 +759,11 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
fileprivate func promptToAppSettings() {
|
fileprivate func promptToAppSettings() {
|
||||||
guard promptToAppPrivacySettings == true else {
|
guard promptToAppPrivacySettings == true else {
|
||||||
// Do not prompt user
|
// Do not prompt user
|
||||||
// Ca// delegate function SwiftyCamDidFailCameraPermissionSettings()
|
// Call delegate function SwiftyCamDidFailCameraPermissionSettings()
|
||||||
self.cameraDelegate?.SwiftyCamDidFailCameraPermissionSettings()
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidFailCameraPermissionSettings()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -939,7 +956,9 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
||||||
print("[SwiftyCam]: Movie file finishing error: \(error)")
|
print("[SwiftyCam]: Movie file finishing error: \(error)")
|
||||||
} else {
|
} else {
|
||||||
//Call delegate function with the URL of the outputfile
|
//Call delegate function with the URL of the outputfile
|
||||||
self.cameraDelegate?.SwiftyCamDidFinishProcessingVideoAt(outputFileURL)
|
DispatchQueue.main.async {
|
||||||
|
self.cameraDelegate?.SwiftyCamDidFinishProcessingVideoAt(outputFileURL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||