Commit c9c3e1d5 by Daniel Dahan

added flash and torch mode to CaptureSession

parent 16f980b2
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_off_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_on_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -204,6 +204,7 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
*/
internal func handleTapToResetGesture(recognizer: UITapGestureRecognizer) {
if tapToResetEnabled {
captureSession.resetFocusAndExposureModes()
(delegate as? CapturePreviewViewDelegate)?.capturePreviewViewDidTapToResetAtPoint?(self, point: pointForCaptureDevicePointOfInterest(CGPointMake(0.5, 0.5)))
}
}
......
......@@ -129,14 +129,28 @@ public class CaptureSession : NSObject {
:name: caneraSupportsTapToFocus
*/
public var cameraSupportsTapToFocus: Bool {
return true == activeCamera?.focusPointOfInterestSupported
return activeCamera!.focusPointOfInterestSupported
}
/**
:name: cameraSupportsTapToExpose
*/
public var cameraSupportsTapToExpose: Bool {
return true == activeCamera?.exposurePointOfInterestSupported
return activeCamera!.exposurePointOfInterestSupported
}
/**
:name: cameraHasFlash
*/
public var cameraHasFlash: Bool {
return activeCamera!.hasFlash
}
/**
:name: cameraHasTorch
*/
public var cameraHasTorch: Bool {
return activeCamera!.hasTorch
}
/**
......@@ -167,6 +181,60 @@ public class CaptureSession : NSObject {
}
/**
:name: flashMode
*/
public var flashMode: AVCaptureFlashMode {
get {
return activeCamera!.flashMode
}
set(value) {
var error: NSError?
if isFlashModeSupported(flashMode) {
do {
let device: AVCaptureDevice = activeCamera!
try device.lockForConfiguration()
device.flashMode = flashMode
device.unlockForConfiguration()
} catch let e as NSError {
error = e
}
} else {
error = NSError(domain: "[MaterialKit Error: Unsupported flashMode.]", code: 0, userInfo: nil)
}
if let e: NSError = error {
delegate?.captureSessionFailedWithError?(self, error: e)
}
}
}
/**
:name: torchMode
*/
public var torchMode: AVCaptureTorchMode {
get {
return activeCamera!.torchMode
}
set(value) {
var error: NSError?
if isTorchModeSupported(torchMode) {
do {
let device: AVCaptureDevice = activeCamera!
try device.lockForConfiguration()
device.torchMode = torchMode
device.unlockForConfiguration()
} catch let e as NSError {
error = e
}
} else {
error = NSError(domain: "[MaterialKit Error: Unsupported torchMode.]", code: 0, userInfo: nil)
}
if let e: NSError = error {
delegate?.captureSessionFailedWithError?(self, error: e)
}
}
}
/**
:name: sessionPreset
*/
public var sessionPreset: CaptureSessionPreset {
......@@ -242,6 +310,20 @@ public class CaptureSession : NSObject {
}
/**
:name: isFlashModeSupported
*/
public func isFlashModeSupported(flashMode: AVCaptureFlashMode) -> Bool {
return activeVideoInput!.device.isFlashModeSupported(flashMode)
}
/**
:name: isTorchModeSupported
*/
public func isTorchModeSupported(torchMode: AVCaptureTorchMode) -> Bool {
return activeVideoInput!.device.isTorchModeSupported(torchMode)
}
/**
:name: focusAtPoint
*/
public func focusAtPoint(point: CGPoint) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment