Skip to content

Commit

Permalink
Merge pull request hyperoslo#224 from rlmartin/option-default-to-fron…
Browse files Browse the repository at this point in the history
…t-camera

Add option to default to the front camera instead of the back camera
  • Loading branch information
RamonGilabert authored Oct 27, 2016
2 parents 36db6a2 + e239eed commit 462aa8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Source/CameraView/CameraMan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class CameraMan {
var backCamera: AVCaptureDeviceInput?
var frontCamera: AVCaptureDeviceInput?
var stillImageOutput: AVCaptureStillImageOutput?
var startOnFrontCamera: Bool = false

deinit {
stop()
}

// MARK: - Setup

func setup() {
func setup(_ startOnFrontCamera: Bool = false) {
self.startOnFrontCamera = startOnFrontCamera
checkPermission()
}

Expand Down Expand Up @@ -100,7 +102,7 @@ class CameraMan {
// Devices
setupDevices()

guard let input = backCamera, let output = stillImageOutput else { return }
guard let input = (self.startOnFrontCamera) ? frontCamera ?? backCamera : backCamera, let output = stillImageOutput else { return }

addInput(input)

Expand Down
3 changes: 2 additions & 1 deletion Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
weak var delegate: CameraViewDelegate?
var animationTimer: Timer?
var locationManager: LocationManager?
var startOnFrontCamera: Bool = false

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -105,7 +106,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate, CameraManDelegate
view.addGestureRecognizer(tapGestureRecognizer)

cameraMan.delegate = self
cameraMan.setup()
cameraMan.setup(self.startOnFrontCamera)
}

override func viewDidAppear(_ animated: Bool) {
Expand Down
2 changes: 2 additions & 0 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ open class ImagePickerController: UIViewController {
lazy var cameraController: CameraView = { [unowned self] in
let controller = CameraView()
controller.delegate = self
controller.startOnFrontCamera = self.startOnFrontCamera

return controller
}()
Expand All @@ -70,6 +71,7 @@ open class ImagePickerController: UIViewController {
open var stack = ImageStack()
open var imageLimit = 0
open var preferredImageSize: CGSize?
open var startOnFrontCamera = false
var totalSize: CGSize { return UIScreen.main.bounds.size }
var initialFrame: CGRect?
var initialContentOffset: CGPoint?
Expand Down

0 comments on commit 462aa8b

Please sign in to comment.