Skip to content

Commit

Permalink
flash mode and flash check added
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhanmandaci committed Feb 21, 2020
1 parent c663ae0 commit 3ce6d88
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Example/FMCamera/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<constraint firstAttribute="width" constant="50" id="926-zF-kQv"/>
</constraints>
<state key="normal" image="cameraFlash"/>
<connections>
<action selector="btnFlashAction:" destination="DVJ-ff-9PM" eventType="touchUpInside" id="deX-tQ-3wA"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="orK-tl-cB9">
<rect key="frame" x="90" y="0.0" width="89" height="89"/>
Expand Down Expand Up @@ -87,6 +90,7 @@
<viewLayoutGuide key="safeArea" id="tcd-AL-YhK"/>
</view>
<connections>
<outlet property="btnFlash" destination="I0a-kQ-Uji" id="3MT-4h-V3v"/>
<outlet property="imgCapture" destination="6qG-Vq-5kK" id="gZx-uO-tgc"/>
<outlet property="vwSquareCamera" destination="KmM-cI-3fC" id="4CK-2J-jpf"/>
<outlet property="vwVideoPlayer" destination="cfe-EE-cef" id="ClJ-t2-Kyw"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "cameraFlashOpen.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "cameraFlashOpen@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "cameraFlashOpen@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 28 additions & 14 deletions Example/FMCamera/MainVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ class MainVC: UIViewController {
@IBOutlet weak var vwSquareCamera: FMCamera!
@IBOutlet weak var vwVideoPlayer: UIView!
@IBOutlet weak var imgCapture: UIImageView!
@IBOutlet weak var btnFlash: UIButton!

// MARK: - Actions
@IBAction func btnCaptureAction(_ sender: Any) {
if !vwSquareCamera.isCameraRecording {
vwVideoPlayer.isHidden = true
if avPlayer != nil {
avPlayer?.pause()
avPlayer = nil
}
avPlayerLayer?.removeFromSuperlayer()
avPlayerLayer = nil
vwSquareCamera.startRecording()
} else {
vwSquareCamera.stopRecording()
}
// vwSquareCamera.maxPictureFileSize = 250000
// vwSquareCamera.takePhoto()
// if !vwSquareCamera.isCameraRecording {
// vwVideoPlayer.isHidden = true
// if avPlayer != nil {
// avPlayer?.pause()
// avPlayer = nil
// }
// avPlayerLayer?.removeFromSuperlayer()
// avPlayerLayer = nil
// vwSquareCamera.startRecording()
// } else {
// vwSquareCamera.stopRecording()
// }
vwSquareCamera.maxPictureFileSize = 250000
vwSquareCamera.takePhoto()
}

@IBAction func btnFlipCameraAction(_ sender: Any) {
Expand All @@ -49,6 +50,19 @@ class MainVC: UIViewController {
}
}

@IBAction func btnFlashAction(_ sender: Any) {
switch vwSquareCamera.flashMode {
case .off, .auto:
vwSquareCamera.flashMode = .on
btnFlash.setImage(UIImage(named: "cameraFlashOpen"), for: .normal)
case .on:
vwSquareCamera.flashMode = .off
btnFlash.setImage(UIImage(named: "cameraFlash"), for: .normal)
@unknown default:
break
}
}

// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
Expand Down
2 changes: 1 addition & 1 deletion FMCamera.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'FMCamera'
s.version = '1.0.6'
s.version = '1.0.7'
s.summary = 'FMCamera is a simple camera view which let us capture photo or video in a given size.'

# This description is used to generate tags and improve search results.
Expand Down
9 changes: 8 additions & 1 deletion Source/FMCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,14 @@ extension FMCamera {
AVVideoCodecKey: AVVideoCodecType.jpeg
])
}
settings.flashMode = flashMode

if let dInput = deviceInput {
if dInput.device.hasFlash {
settings.flashMode = flashMode
} else {
settings.flashMode = .off
}
}
stillImageOutput.capturePhoto(with: settings, delegate: self)
} else {
print("SC CAMERA ERROR: Please configure your camera view before taking photo. ( Call configure() )")
Expand Down

0 comments on commit 3ce6d88

Please sign in to comment.