mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Forget the flash/torch nonsense
This commit is contained in:
parent
5b50330d72
commit
a81edae04f
13 changed files with 8 additions and 221 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 935 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB |
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB |
|
|
@ -1,11 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
|
|
@ -36,40 +33,26 @@
|
|||
<action selector="cameraSwitchTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Du6-FK-hjA"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="stR-Rn-UdV">
|
||||
<rect key="frame" x="275" y="594.5" width="18" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="8dD-oU-QV8"/>
|
||||
<constraint firstAttribute="width" constant="18" id="rLN-FU-RYb"/>
|
||||
</constraints>
|
||||
<state key="normal" image="flashOutline"/>
|
||||
<connections>
|
||||
<action selector="toggleFlashTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="C5u-0g-Kim"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="hke-fJ-4fX" secondAttribute="bottom" constant="20" symbolic="YES" id="0OM-Pc-Ze1"/>
|
||||
<constraint firstItem="hke-fJ-4fX" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="22M-gB-uKl"/>
|
||||
<constraint firstItem="stR-Rn-UdV" firstAttribute="leading" secondItem="hke-fJ-4fX" secondAttribute="trailing" constant="50" id="4S2-fF-Ta9"/>
|
||||
<constraint firstItem="hS2-sy-kuv" firstAttribute="centerY" secondItem="hke-fJ-4fX" secondAttribute="centerY" id="AuI-5x-aKM"/>
|
||||
<constraint firstItem="hke-fJ-4fX" firstAttribute="leading" secondItem="hS2-sy-kuv" secondAttribute="trailing" constant="50" id="fY6-aF-vVL"/>
|
||||
<constraint firstItem="stR-Rn-UdV" firstAttribute="centerY" secondItem="hke-fJ-4fX" secondAttribute="centerY" id="sJP-2Z-GAn"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="captureButton" destination="hke-fJ-4fX" id="nng-T2-6kL"/>
|
||||
<outlet property="flashButton" destination="stR-Rn-UdV" id="WAJ-Ik-VF7"/>
|
||||
<outlet property="flipCameraButton" destination="hS2-sy-kuv" id="lWF-Wl-Vg1"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-26" y="-24"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="flashOutline" width="18" height="30"/>
|
||||
<image name="flipCamera" width="30" height="23"/>
|
||||
</resources>
|
||||
</document>
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue