Preview view addition initialiser parameters optional.

This commit is contained in:
nelanelanela 2014-10-15 15:21:21 +01:00
parent 664de83760
commit f5b2384964
6 changed files with 67 additions and 42 deletions

View File

@ -4,7 +4,7 @@
V1.0.0 (10-Oct-2014)
####About
This is a simple class to provide all the configurations you need to create custom camera view in your app.
This is a simple class to provide all the configurations and you need to create custom camera view in your app.
Just drag, drop and use.
####How to use

View File

@ -23,8 +23,6 @@
454C1F4B19E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
454C1F4D19E82E2500C81915 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
454C1F5019E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
454C1F5B19E82E2500C81915 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
454C1F5C19E82E2500C81915 /* cameraTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = cameraTests.swift; sourceTree = "<group>"; };
454C1F6619E8316A00C81915 /* CameraManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -43,7 +41,6 @@
isa = PBXGroup;
children = (
454C1F4319E82E2500C81915 /* camera */,
454C1F5919E82E2500C81915 /* cameraTests */,
454C1F4219E82E2500C81915 /* Products */,
);
sourceTree = "<group>";
@ -78,23 +75,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
454C1F5919E82E2500C81915 /* cameraTests */ = {
isa = PBXGroup;
children = (
454C1F5C19E82E2500C81915 /* cameraTests.swift */,
454C1F5A19E82E2500C81915 /* Supporting Files */,
);
path = cameraTests;
sourceTree = "<group>";
};
454C1F5A19E82E2500C81915 /* Supporting Files */ = {
isa = PBXGroup;
children = (
454C1F5B19E82E2500C81915 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -314,6 +294,7 @@
454C1F6219E82E2500C81915 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>B6656DA7-2538-41EB-B435-476DC073ECE9</string>
<key>IDESourceControlProjectName</key>
<string>camera</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E1D0A3AE6B49B031DF6A25973E5414F28D2A575A</key>
<string>https://github.com/imaginary-cloud/CameraManager.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>camera.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E1D0A3AE6B49B031DF6A25973E5414F28D2A575A</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/imaginary-cloud/CameraManager.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E1D0A3AE6B49B031DF6A25973E5414F28D2A575A</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E1D0A3AE6B49B031DF6A25973E5414F28D2A575A</string>
<key>IDESourceControlWCCName</key>
<string>camera</string>
</dict>
</array>
</dict>
</plist>

View File

@ -34,8 +34,13 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
/// Capture sessioc to customize camera settings.
var captureSession: AVCaptureSession?
/// Property to determine if the manager should show the error for the user.
/// Property to determine if the manager should show the error for the user. If you want to show the errors yourself set this to false. If you want to add custom error UI set showErrorBlock property
var showErrorsToUsers = true
/// A block creating UI to present error message to the user.
var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
}
/// The Bool property to determin if current device has front camera.
var hasFrontCamera: Bool = {
@ -49,11 +54,6 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
return false
}()
/// A block creating UI to present error message to the user.
var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
}
/// Property to change camera device between front and back.
var cameraDevice: CameraDevice {
get {
@ -175,7 +175,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
switch newCameraOutputMode {
case .StillImage:
if (self.stillImageOutput == nil) {
self._setupStillImageOutput()
self._setupOutputs()
}
if let validStillImageOutput = self.stillImageOutput? {
self.captureSession?.addOutput(validStillImageOutput)
@ -184,7 +184,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
case .VideoOnly, .VideoWithMic:
if (self.movieOutput == nil) {
self._setupMovieOutput()
self._setupOutputs()
}
if let validMovieOutput = self.movieOutput? {
self.captureSession?.addOutput(validMovieOutput)
@ -250,7 +250,11 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
:param: view The view you want to add the preview layer to
:param: cameraOutputMode The mode you want capturesession to run image / video / video and microphone
*/
func addPreeviewLayerToView(view: UIView, cameraOutputMode: CameraOutputMode)
func addPreeviewLayerToView(view: UIView)
{
self.addPreeviewLayerToView(view, newCameraOutputMode: self.currentCameraOutputMode)
}
func addPreeviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode)
{
if let validEmbedingView = self.embedingView? {
if let validPreviewLayer = self.previewLayer? {
@ -259,11 +263,11 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if self.cameraIsSetup {
self._addPreeviewLayerToView(view)
self.cameraOutputMode = cameraOutputMode
self.cameraOutputMode = newCameraOutputMode
} else {
self._setupCamera({ Void -> Void in
self._addPreeviewLayerToView(view)
self.cameraOutputMode = cameraOutputMode
self.cameraOutputMode = newCameraOutputMode
})
}
}
@ -413,8 +417,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if let validCaptureSession = self.captureSession? {
validCaptureSession.beginConfiguration()
self._addVideoInput()
self._setupStillImageOutput()
self._setupMovieOutput()
self._setupOutputs()
self.cameraOutputMode = self.currentCameraOutputMode
self._setupPreviewLayer()
validCaptureSession.commitConfiguration()
@ -494,20 +497,16 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
}
}
private func _setupStillImageOutput()
private func _setupOutputs()
{
if (self.stillImageOutput == nil) {
self.stillImageOutput = AVCaptureStillImageOutput()
}
}
private func _setupMovieOutput()
{
if (self.movieOutput == nil) {
self.movieOutput = AVCaptureMovieFileOutput()
}
}
private func _setupPreviewLayer()
{
if let validCaptureSession = self.captureSession? {

View File

@ -18,10 +18,14 @@ class ViewController: UIViewController {
override func viewDidLoad()
{
super.viewDidLoad()
self.cameraManager.addPreeviewLayerToView(self.cameraView, cameraOutputMode: CameraOutputMode.VideoWithMic)
super.viewDidLoad()
self.cameraManager.addPreeviewLayerToView(self.cameraView, newCameraOutputMode: CameraOutputMode.VideoWithMic)
CameraManager.sharedInstance.addPreeviewLayerToView(self.cameraView)
self.cameraManager.cameraDevice = .Front
self.imageView.hidden = true
CameraManager.sharedInstance.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
}
}
@IBAction func changeFlashMode(sender: UIButton)