Camera lifcycle enhenced.

This commit is contained in:
nelanelanela 2014-10-21 09:32:05 +01:00
parent 588af2df0d
commit e98520ad37
3 changed files with 31 additions and 4 deletions

View File

@ -281,9 +281,9 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
}
/**
Restarts capture session.
Resumes capture session.
*/
func restartCaptureSession()
func resumeCaptureSession()
{
if let validCaptureSession = self.captureSession? {
validCaptureSession.startRunning()
@ -291,7 +291,11 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if self.cameraIsSetup {
self.stopAndRemoveCaptureSession()
}
self._setupCamera({Void -> Void in })
self._setupCamera({Void -> Void in
if let validEmbedingView = self.embedingView? {
self._addPreeviewLayerToView(validEmbedingView)
}
})
}
}
@ -463,8 +467,9 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
validCaptureSession.commitConfiguration()
validCaptureSession.startRunning()
self._startFollowingDeviceOrientation()
completition()
self.cameraIsSetup = true
completition()
}
})
} else {

View File

@ -10,12 +10,19 @@ import UIKit
class ViewController: UIViewController {
// MARK: - Constants
let cameraManager = CameraManager.sharedInstance
// MARK: - @IBOutlets
@IBOutlet weak var cameraView: UIView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var cameraButton: UIButton!
// MARK: - UIViewController
override func viewDidLoad()
{
super.viewDidLoad()
@ -27,6 +34,21 @@ class ViewController: UIViewController {
}
}
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
self.cameraManager.resumeCaptureSession()
}
override func viewWillDisappear(animated: Bool)
{
super.viewWillDisappear(animated)
self.cameraManager.stopCaptureSession()
}
// MARK: - @IBActions
@IBAction func changeFlashMode(sender: UIButton)
{
self.cameraManager.flashMode = CameraFlashMode.fromRaw((self.cameraManager.flashMode.toRaw()+1)%3)!