@@ -155,16 +155,21 @@ open class CameraViewController: UIViewController {
155155 view. translatesAutoresizingMaskIntoConstraints = false
156156 return view
157157 } ( )
158+
159+ private let allowsLibraryAccess : Bool
158160
159- public init ( croppingEnabled: Bool , allowsLibraryAccess: Bool = true , completion: @escaping CameraViewCompletion ) {
161+ public init ( croppingEnabled: Bool , allowsLibraryAccess: Bool = true , allowsSwapCameraOrientation: Bool = true , completion: @escaping CameraViewCompletion ) {
162+ self . allowsLibraryAccess = allowsLibraryAccess
160163 super. init ( nibName: nil , bundle: nil )
161164 onCompletion = completion
162165 allowCropping = croppingEnabled
163166 cameraOverlay. isHidden = !allowCropping
164167 libraryButton. isEnabled = allowsLibraryAccess
165168 libraryButton. isHidden = !allowsLibraryAccess
169+ swapButton. isEnabled = allowsSwapCameraOrientation
170+ swapButton. isHidden = !allowsSwapCameraOrientation
166171 }
167-
172+
168173 required public init ? ( coder aDecoder: NSCoder ) {
169174 fatalError ( " init(coder:) has not been implemented " )
170175 }
@@ -386,8 +391,8 @@ open class CameraViewController: UIViewController {
386391 internal func rotate( actualInterfaceOrientation: UIInterfaceOrientation ) {
387392
388393 if lastInterfaceOrientation != nil {
389- let lastTransform = CGAffineTransform ( rotationAngle: CGFloat ( radians ( currentRotation (
390- lastInterfaceOrientation!, newOrientation: actualInterfaceOrientation) ) ) )
394+ let lastTransform = CGAffineTransform ( rotationAngle: radians ( currentRotation (
395+ lastInterfaceOrientation!, newOrientation: actualInterfaceOrientation) ) )
391396 setTransform ( transform: lastTransform)
392397 }
393398
@@ -502,6 +507,7 @@ open class CameraViewController: UIViewController {
502507 let spinner = showSpinner ( )
503508 cameraView. preview. isHidden = true
504509
510+ if allowsLibraryAccess {
505511 _ = SingleImageSaver ( )
506512 . setImage ( image)
507513 . onSuccess { [ weak self] asset in
@@ -515,8 +521,12 @@ open class CameraViewController: UIViewController {
515521 self ? . hideSpinner ( spinner)
516522 }
517523 . save ( )
524+ } else {
525+ layoutCameraResult ( uiImage: image)
526+ hideSpinner ( spinner)
527+ }
518528 }
519-
529+
520530 internal func close( ) {
521531 onCompletion ? ( nil , nil )
522532 onCompletion = nil
@@ -558,13 +568,37 @@ open class CameraViewController: UIViewController {
558568 cameraView. swapCameraInput ( )
559569 flashButton. isHidden = cameraView. currentPosition == AVCaptureDevicePosition . front
560570 }
561-
571+
572+ internal func layoutCameraResult( uiImage: UIImage ) {
573+ cameraView. stopSession ( )
574+ startConfirmController ( uiImage: uiImage)
575+ toggleButtons ( enabled: true )
576+ }
577+
562578 internal func layoutCameraResult( asset: PHAsset ) {
563579 cameraView. stopSession ( )
564580 startConfirmController ( asset: asset)
565581 toggleButtons ( enabled: true )
566582 }
567-
583+
584+ private func startConfirmController( uiImage: UIImage ) {
585+ let confirmViewController = ConfirmViewController ( image: uiImage, allowsCropping: allowCropping)
586+ confirmViewController. onComplete = { [ weak self] image, asset in
587+ defer {
588+ self ? . dismiss ( animated: true , completion: nil )
589+ }
590+
591+ guard let image = image else {
592+ return
593+ }
594+
595+ self ? . onCompletion ? ( image, asset)
596+ self ? . onCompletion = nil
597+ }
598+ confirmViewController. modalTransitionStyle = UIModalTransitionStyle . crossDissolve
599+ present ( confirmViewController, animated: true , completion: nil )
600+ }
601+
568602 private func startConfirmController( asset: PHAsset ) {
569603 let confirmViewController = ConfirmViewController ( asset: asset, allowsCropping: allowCropping)
570604 confirmViewController. onComplete = { [ weak self] image, asset in
0 commit comments