Skip to content

Commit

Permalink
Merge pull request #99 from hyperoslo/fix/torch-mode
Browse files Browse the repository at this point in the history
Fix torch mode for front camera
  • Loading branch information
vadymmarkov authored Feb 1, 2018
2 parents 6eee165 + 4a8ae52 commit 05f16d5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Controllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public final class CameraViewController: UIViewController {
private var torchMode: TorchMode = .off {
didSet {
guard let captureDevice = captureDevice, captureDevice.hasFlash else { return }
guard captureDevice.isTorchModeSupported(torchMode.captureTorchMode) else { return }

do {
try captureDevice.lockForConfiguration()
Expand Down Expand Up @@ -138,7 +139,8 @@ public final class CameraViewController: UIViewController {
torchMode = .off
captureSession.startRunning()
focusView.isHidden = false
flashButton.isHidden = false
flashButton.isHidden = captureDevice?.position == .front
cameraButton.isHidden = !showsCameraButton
}

func stopCapturing() {
Expand All @@ -150,6 +152,7 @@ public final class CameraViewController: UIViewController {
captureSession.stopRunning()
focusView.isHidden = true
flashButton.isHidden = true
cameraButton.isHidden = true
}

// MARK: - Actions
Expand Down Expand Up @@ -243,6 +246,7 @@ public final class CameraViewController: UIViewController {
}
captureSession.addInput(newInput)
captureSession.commitConfiguration()
flashButton.isHidden = position == .front
} catch {
delegate?.cameraViewController(self, didReceiveError: error)
return
Expand Down Expand Up @@ -423,7 +427,7 @@ private extension CameraViewController {
func makeCameraButton() -> UIButton {
let button = UIButton(type: .custom)
button.setImage(imageNamed("cameraRotate"), for: UIControlState())
button.isHidden = showsCameraButton
button.isHidden = !showsCameraButton
return button
}
}
Expand Down

0 comments on commit 05f16d5

Please sign in to comment.