mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Merge branch 'feature/swift4-auto-flash' into develop
This commit is contained in:
commit
a9eda5fc0d
7 changed files with 102 additions and 38 deletions
|
|
@ -188,8 +188,8 @@
|
||||||
};
|
};
|
||||||
1675A9711E00A68300B80903 = {
|
1675A9711E00A68300B80903 = {
|
||||||
CreatedOnToolsVersion = 8.1;
|
CreatedOnToolsVersion = 8.1;
|
||||||
LastSwiftMigration = 0900;
|
DevelopmentTeam = KNZW2F3F6V;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Manual;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -443,12 +443,15 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = "";
|
CODE_SIGN_STYLE = Manual;
|
||||||
|
DEVELOPMENT_TEAM = KNZW2F3F6V;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
PROVISIONING_PROFILE = "392470bd-cfda-4593-a8ca-cd9af3eef31e";
|
||||||
|
PROVISIONING_PROFILE_SPECIFIER = "Officina Development Generic";
|
||||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 4.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
|
|
@ -459,12 +462,15 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = "";
|
CODE_SIGN_STYLE = Manual;
|
||||||
|
DEVELOPMENT_TEAM = KNZW2F3F6V;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
PROVISIONING_PROFILE = "392470bd-cfda-4593-a8ca-cd9af3eef31e";
|
||||||
|
PROVISIONING_PROFILE_SPECIFIER = "Officina Development Generic";
|
||||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 4.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@
|
||||||
"idiom" : "iphone",
|
"idiom" : "iphone",
|
||||||
"size" : "60x60",
|
"size" : "60x60",
|
||||||
"scale" : "3x"
|
"scale" : "3x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ios-marketing",
|
||||||
|
"size" : "1024x1024",
|
||||||
|
"scale" : "1x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|
|
||||||
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/Contents.json
vendored
Normal file
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@2x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@3x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/flashauto.imageset/flashauto@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
|
|
@ -31,8 +31,8 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
shouldUseDeviceOrientation = true
|
shouldUseDeviceOrientation = true
|
||||||
allowAutoRotate = true
|
allowAutoRotate = true
|
||||||
audioEnabled = true
|
audioEnabled = true
|
||||||
|
flashMode = .auto
|
||||||
// disable capture button until session starts
|
flashButton.setImage(#imageLiteral(resourceName: "flashauto"), for: UIControlState())
|
||||||
captureButton.buttonEnabled = false
|
captureButton.buttonEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func toggleFlashTapped(_ sender: Any) {
|
@IBAction func toggleFlashTapped(_ sender: Any) {
|
||||||
flashEnabled = !flashEnabled
|
//flashEnabled = !flashEnabled
|
||||||
toggleFlashAnimation()
|
toggleFlashAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,10 +152,16 @@ extension ViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func toggleFlashAnimation() {
|
fileprivate func toggleFlashAnimation() {
|
||||||
if flashEnabled == true {
|
//flashEnabled = !flashEnabled
|
||||||
|
if flashMode == .auto{
|
||||||
|
flashMode = .on
|
||||||
flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState())
|
flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState())
|
||||||
} else {
|
}else if flashMode == .on{
|
||||||
|
flashMode = .off
|
||||||
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
||||||
|
}else if flashMode == .off{
|
||||||
|
flashMode = .auto
|
||||||
|
flashButton.setImage(#imageLiteral(resourceName: "flashauto"), for: UIControlState())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*Copyright (c) 2016, Andrew Walz.
|
/*Copyright (c) 2016, Andrew Walz.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
|
@ -35,6 +35,18 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
/// Camera on the front of the device
|
/// Camera on the front of the device
|
||||||
case front = "front"
|
case front = "front"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum FlashMode{
|
||||||
|
|
||||||
|
//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
|
/// Enumeration for video quality of the capture session. Corresponds to a AVCaptureSessionPreset
|
||||||
|
|
||||||
|
|
@ -102,8 +114,11 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
public var videoQuality : VideoQuality = .high
|
public var videoQuality : VideoQuality = .high
|
||||||
|
|
||||||
/// Sets whether flash is enabled for photo and video capture
|
/// Sets whether flash is enabled for photo and video capture
|
||||||
|
@available(*, deprecated, message: "use flashMode .on or .off") //use flashMode
|
||||||
public var flashEnabled = false
|
public var flashEnabled = false
|
||||||
|
|
||||||
|
// Flash Mode
|
||||||
|
public var flashMode:FlashMode = .off
|
||||||
|
|
||||||
/// Sets whether Pinch to Zoom is enabled for the capture session
|
/// Sets whether Pinch to Zoom is enabled for the capture session
|
||||||
|
|
||||||
|
|
@ -448,32 +463,32 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if device.hasFlash == true && flashMode != .off /* TODO: Add Support for Retina Flash and add front flash */ {
|
||||||
if device.hasFlash == true && flashEnabled == true /* TODO: Add Support for Retina Flash and add front flash */ {
|
changeFlashSettings(device: device, mode: flashMode)
|
||||||
changeFlashSettings(device: device, mode: .on)
|
|
||||||
capturePhotoAsyncronously(completionHandler: { (_) in })
|
capturePhotoAsyncronously(completionHandler: { (_) in })
|
||||||
|
|
||||||
} else if device.hasFlash == false && flashEnabled == true && currentCamera == .front {
|
// } else if device.hasFlash == false && flashMode == .on && currentCamera == .front {
|
||||||
flashView = UIView(frame: view.frame)
|
// flashView = UIView(frame: view.frame)
|
||||||
flashView?.alpha = 0.0
|
// flashView?.alpha = 0.0
|
||||||
flashView?.backgroundColor = UIColor.white
|
// flashView?.backgroundColor = UIColor.white
|
||||||
previewLayer.addSubview(flashView!)
|
// previewLayer.addSubview(flashView!)
|
||||||
|
//
|
||||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
// UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||||
self.flashView?.alpha = 1.0
|
// self.flashView?.alpha = 1.0
|
||||||
|
//
|
||||||
}, completion: { (_) in
|
// }, completion: { (_) in
|
||||||
self.capturePhotoAsyncronously(completionHandler: { (success) in
|
// self.capturePhotoAsyncronously(completionHandler: { (success) in
|
||||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
// UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||||
self.flashView?.alpha = 0.0
|
// self.flashView?.alpha = 0.0
|
||||||
}, completion: { (_) in
|
// }, completion: { (_) in
|
||||||
self.flashView?.removeFromSuperview()
|
// self.flashView?.removeFromSuperview()
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
} else {
|
// } else {
|
||||||
|
}else{
|
||||||
if device.isFlashActive == true {
|
if device.isFlashActive == true {
|
||||||
changeFlashSettings(device: device, mode: .off)
|
changeFlashSettings(device: device, mode: flashMode)
|
||||||
}
|
}
|
||||||
capturePhotoAsyncronously(completionHandler: { (_) in })
|
capturePhotoAsyncronously(completionHandler: { (_) in })
|
||||||
}
|
}
|
||||||
|
|
@ -497,11 +512,11 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentCamera == .rear && flashEnabled == true {
|
if currentCamera == .rear && flashMode == .on {
|
||||||
enableFlash()
|
enableFlash()
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentCamera == .front && flashEnabled == true {
|
if currentCamera == .front && flashMode == .on {
|
||||||
flashView = UIView(frame: view.frame)
|
flashView = UIView(frame: view.frame)
|
||||||
flashView?.backgroundColor = UIColor.white
|
flashView?.backgroundColor = UIColor.white
|
||||||
flashView?.alpha = 0.85
|
flashView?.alpha = 0.85
|
||||||
|
|
@ -559,7 +574,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
movieFileOutput!.stopRecording()
|
movieFileOutput!.stopRecording()
|
||||||
disableFlash()
|
disableFlash()
|
||||||
|
|
||||||
if currentCamera == .front && flashEnabled == true && flashView != nil {
|
if currentCamera == .front && flashMode == .on && flashView != nil {
|
||||||
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||||
self.flashView?.alpha = 0.0
|
self.flashView?.alpha = 0.0
|
||||||
}, completion: { (_) in
|
}, completion: { (_) in
|
||||||
|
|
@ -909,9 +924,19 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
/// Enable or disable flash for photo
|
/// Enable or disable flash for photo
|
||||||
|
|
||||||
fileprivate func changeFlashSettings(device: AVCaptureDevice, mode: AVCaptureDevice.FlashMode) {
|
fileprivate func changeFlashSettings(device: AVCaptureDevice, mode: FlashMode) {
|
||||||
do {
|
do {
|
||||||
try device.lockForConfiguration()
|
try device.lockForConfiguration()
|
||||||
|
let mode:AVCaptureDevice.FlashMode
|
||||||
|
switch flashMode{
|
||||||
|
case .on:
|
||||||
|
mode = .on
|
||||||
|
case .off:
|
||||||
|
mode = .off
|
||||||
|
case .auto:
|
||||||
|
mode = .auto
|
||||||
|
|
||||||
|
}
|
||||||
device.flashMode = mode
|
device.flashMode = mode
|
||||||
device.unlockForConfiguration()
|
device.unlockForConfiguration()
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue