         
     }
     
-    @objc fileprivate func _handleToggleFace(_ sender: UIButton) { let _ = try? _previewView.toggle() }
+    @objc fileprivate func _handleToggleFace(_ sender: UIButton) {
+        _sessionQueue.async { [unowned self] in
+            let _ = try? self._previewView.toggle()
+        }
+        // Add transition animation.
+        let transition = CATransition()
+        // cube, suckEffect, oglFlip, rippleEffect, pageCurl, pageUnCurl, cameraIrisHollowOpen, cameraIrisHollowClose
+        transition.type = "oglFlip"
+        transition.subtype = kCATransitionFromLeft
+        transition.duration = 0.25 * 2.0
+        self.previewView.layer.add(transition, forKey: "transition")
+    }
     
     @objc
     fileprivate func _handleCancel(_ sender: UIButton) {

@objc public protocol CameraViewControllerDelegate {
    @objc optional func cameraViewControllerDidCancel(_ cameraViewController: CameraViewController)
}

@available(iOS 9.0, *)
open class CameraViewController: UIViewController {
    open weak var delegate: CameraViewControllerDelegate?
    open   var stopSessionWhenDisposed: Bool = false
    public var configurationQueue: DispatchQueue { return _sessionQueue }
    /// Sample buffer delegates queue.
    fileprivate
    var _sampleBufferDelegates: NSHashTable<AVCaptureVideoDataOutputSampleBufferDelegate> = NSHashTable.weakObjects()
    
    private var _session: AVCaptureSession!
    private var _input  : AVCaptureDeviceInput!
    private var _output : AVCapturePhotoOutput!
    
    public var previewView: CaptureVideoPreviewView! { return _previewView }
    fileprivate var _previewView: CaptureVideoPreviewView!
    
    // MARK: Tool Views.
    
    private let _flashConfigs: [(title: String, image: UIImage)] = [("自动", #imageLiteral(resourceName: "flash_auto")), ("打开", #imageLiteral(resourceName: "flash_on")), ("关闭", #imageLiteral(resourceName: "flash_off"))]
    private let _hdrConfigs: [(title: String, image: UIImage)] = [("自动", UIImage(named: _Resource.bundle+"HDR_auto")!), ("打开", UIImage(named: _Resource.bundle+"HDR_on")!), ("关闭", UIImage(named: _Resource.bundle+"HDR_off")!)]
    public var topBar: TopBar { return _topBar }
    fileprivate lazy var _topBar: TopBar = { () -> TopBar in
        let topBar = TopBar()
        topBar.tintColor = .white

    override open var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { return .fade }
}

// MARK: - Session

extension CameraViewController {
    /// A type representing the starting time of the session.
    public enum SessionStarting {
        /// A type representing the life cycle of view of the view controller.
        public enum ViewLifeCycle {
            /// Indicates the view is during loading at calling `loadView()`.
            case loading
            /// Indicates the view is loaded at calling of `viewDidLoad()`.
            case loaded
            /// Indicates the view is about to show at calling of `viewWillAppear(_:)`
            case willAppear
            /// Indicates the view is showed at calling of `viewDidAppear(_:)`.
            case didAppear
        }
        /// Indicates the session is never starting or stopping.
        case never
        /// Indicates the session will start at initializing and stop at disposed.
        case immediately
        /// Indicates the session will start at the point of the  life cycle of the view and stop at disposed.
        case at(ViewLifeCycle)
    }
}

// MARK: - CaptureVideoPreviewView.

extension CameraViewController {
