@@ -155,16 +155,21 @@ open class CameraViewController: UIViewController {
155
155
view. translatesAutoresizingMaskIntoConstraints = false
156
156
return view
157
157
} ( )
158
+
159
+ private let allowsLibraryAccess : Bool
158
160
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
160
163
super. init ( nibName: nil , bundle: nil )
161
164
onCompletion = completion
162
165
allowCropping = croppingEnabled
163
166
cameraOverlay. isHidden = !allowCropping
164
167
libraryButton. isEnabled = allowsLibraryAccess
165
168
libraryButton. isHidden = !allowsLibraryAccess
169
+ swapButton. isEnabled = allowsSwapCameraOrientation
170
+ swapButton. isHidden = !allowsSwapCameraOrientation
166
171
}
167
-
172
+
168
173
required public init ? ( coder aDecoder: NSCoder ) {
169
174
fatalError ( " init(coder:) has not been implemented " )
170
175
}
@@ -386,8 +391,8 @@ open class CameraViewController: UIViewController {
386
391
internal func rotate( actualInterfaceOrientation: UIInterfaceOrientation ) {
387
392
388
393
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) ) )
391
396
setTransform ( transform: lastTransform)
392
397
}
393
398
@@ -502,6 +507,7 @@ open class CameraViewController: UIViewController {
502
507
let spinner = showSpinner ( )
503
508
cameraView. preview. isHidden = true
504
509
510
+ if allowsLibraryAccess {
505
511
_ = SingleImageSaver ( )
506
512
. setImage ( image)
507
513
. onSuccess { [ weak self] asset in
@@ -515,8 +521,12 @@ open class CameraViewController: UIViewController {
515
521
self ? . hideSpinner ( spinner)
516
522
}
517
523
. save ( )
524
+ } else {
525
+ layoutCameraResult ( uiImage: image)
526
+ hideSpinner ( spinner)
527
+ }
518
528
}
519
-
529
+
520
530
internal func close( ) {
521
531
onCompletion ? ( nil , nil )
522
532
onCompletion = nil
@@ -558,13 +568,37 @@ open class CameraViewController: UIViewController {
558
568
cameraView. swapCameraInput ( )
559
569
flashButton. isHidden = cameraView. currentPosition == AVCaptureDevicePosition . front
560
570
}
561
-
571
+
572
+ internal func layoutCameraResult( uiImage: UIImage ) {
573
+ cameraView. stopSession ( )
574
+ startConfirmController ( uiImage: uiImage)
575
+ toggleButtons ( enabled: true )
576
+ }
577
+
562
578
internal func layoutCameraResult( asset: PHAsset ) {
563
579
cameraView. stopSession ( )
564
580
startConfirmController ( asset: asset)
565
581
toggleButtons ( enabled: true )
566
582
}
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
+
568
602
private func startConfirmController( asset: PHAsset ) {
569
603
let confirmViewController = ConfirmViewController ( asset: asset, allowsCropping: allowCropping)
570
604
confirmViewController. onComplete = { [ weak self] image, asset in
0 commit comments