From 48b221e5b09a3bd6093c369feb4e43454c1611eb Mon Sep 17 00:00:00 2001 From: Pavan Paruchuri Date: Fri, 28 Oct 2016 10:57:10 +0530 Subject: [PATCH] Hiding the preview once we capture the image and showing the loading indicator until image is saved. Otherwise preview is being shown until all the process is done. --- .../ViewController/CameraViewController.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ALCameraViewController/ViewController/CameraViewController.swift b/ALCameraViewController/ViewController/CameraViewController.swift index e3b12000..daded65f 100644 --- a/ALCameraViewController/ViewController/CameraViewController.swift +++ b/ALCameraViewController/ViewController/CameraViewController.swift @@ -485,14 +485,20 @@ public class CameraViewController: UIViewController { } internal func saveImage(image: UIImage) { + let spinner = showSpinner() + + cameraView.preview.isHidden = true _ = SingleImageSaver() .setImage(image) .onSuccess { asset in + self.hideSpinner(spinner) self.layoutCameraResult(asset: asset) } .onFailure { error in + self.hideSpinner(spinner) self.toggleButtons(enabled: true) self.showNoPermissionsView(library: true) + self.cameraView.preview.isHidden = false } .save() } @@ -558,4 +564,21 @@ public class CameraViewController: UIViewController { present(confirmViewController, animated: true, completion: nil) } + private func showSpinner() -> UIActivityIndicatorView { + let spinner = UIActivityIndicatorView() + spinner.activityIndicatorViewStyle = .white + spinner.center = view.center + spinner.startAnimating() + + view.addSubview(spinner) + view.bringSubview(toFront: spinner) + + return spinner + } + + private func hideSpinner(_ spinner: UIActivityIndicatorView) { + spinner.stopAnimating() + spinner.removeFromSuperview() + } + }