Commit 30b1d92e by Daniel Dahan

updated CaptureView and example project.

parent 0486e49e
......@@ -46,29 +46,38 @@ class ViewController: UIViewController, CaptureSessionDelegate {
let img1: UIImage? = UIImage(named: "ic_flash_auto_white")
let btn1: FlatButton = FlatButton()
btn1.pulseColor = nil
btn1.pulseColor = MaterialColor.white
btn1.pulseFill = true
btn1.setImage(img1, forState: .Normal)
btn1.setImage(img1, forState: .Highlighted)
btn1.addTarget(self, action: "handleFlash:", forControlEvents: .TouchUpInside)
let img2: UIImage? = UIImage(named: "ic_switch_camera_white")
let btn2: FlatButton = FlatButton()
btn2.pulseColor = nil
btn2.pulseColor = MaterialColor.white
btn2.pulseFill = true
btn2.setImage(img2, forState: .Normal)
btn2.setImage(img2, forState: .Highlighted)
let img3: UIImage? = UIImage(named: "ic_photo_camera_white_36pt")
let img3: UIImage? = UIImage(named: "ic_close_white")
let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.white
btn3.pulseFill = true
btn3.setImage(img3, forState: .Normal)
btn3.setImage(img3, forState: .Highlighted)
let img4: UIImage? = UIImage(named: "ic_photo_camera_white_36pt")
let captureButton: FabButton = FabButton()
captureButton.backgroundColor = MaterialColor.grey.darken2
captureButton.borderWidth = .Border4
captureButton.borderColor = MaterialColor.white
captureButton.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.3)
captureButton.borderWidth = .Border2
captureButton.borderColor = MaterialColor.grey.darken1
captureButton.shadowDepth = .None
captureButton.setImage(img3, forState: .Normal)
captureButton.setImage(img3, forState: .Highlighted)
captureButton.setImage(img4, forState: .Normal)
captureButton.setImage(img4, forState: .Highlighted)
captureView.captureSession.delegate = self
captureView.captureButton = captureButton
captureView.flashAutoButton = btn1
captureView.flashButton = btn1
captureView.switchCamerasButton = btn2
view.addSubview(captureView)
......@@ -81,6 +90,7 @@ class ViewController: UIViewController, CaptureSessionDelegate {
MaterialLayout.size(view, child: captureButton, width: 72, height: 72)
view.addSubview(navigationBarView)
navigationBarView.leftButtons = [btn3]
navigationBarView.rightButtons = [btn1, btn2]
}
......@@ -97,8 +107,8 @@ class ViewController: UIViewController, CaptureSessionDelegate {
img = UIImage(named: "ic_flash_off_white")
print("Flash Off")
}
captureView.flashAutoButton?.setImage(img, forState: .Normal)
captureView.flashAutoButton?.setImage(img, forState: .Highlighted)
captureView.flashButton?.setImage(img, forState: .Normal)
captureView.flashButton?.setImage(img, forState: .Highlighted)
}
/**
......
......@@ -322,28 +322,28 @@ public class CaptureSession : NSObject {
:name: isFocusModeSupported
*/
public func isFocusModeSupported(focusMode: AVCaptureFocusMode) -> Bool {
return activeVideoInput!.device.isFocusModeSupported(focusMode)
return activeCamera!.isFocusModeSupported(focusMode)
}
/**
:name: isExposureModeSupported
*/
public func isExposureModeSupported(exposureMode: AVCaptureExposureMode) -> Bool {
return activeVideoInput!.device.isExposureModeSupported(exposureMode)
return activeCamera!.isExposureModeSupported(exposureMode)
}
/**
:name: isFlashModeSupported
*/
public func isFlashModeSupported(flashMode: AVCaptureFlashMode) -> Bool {
return activeVideoInput!.device.isFlashModeSupported(flashMode)
return activeCamera!.isFlashModeSupported(flashMode)
}
/**
:name: isTorchModeSupported
*/
public func isTorchModeSupported(torchMode: AVCaptureTorchMode) -> Bool {
return activeVideoInput!.device.isTorchModeSupported(torchMode)
return activeCamera!.isTorchModeSupported(torchMode)
}
/**
......@@ -438,7 +438,7 @@ public class CaptureSession : NSObject {
}
device.unlockForConfiguration()
} catch let e as NSError {
self.delegate?.captureSessionFailedWithError?(self, error: e)
delegate?.captureSessionFailedWithError?(self, error: e)
}
}
......
......@@ -40,8 +40,8 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
public var captureButton: UIButton? {
didSet {
if let v: UIButton = captureButton {
v.removeTarget(self, action: "handleCapture:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleCapture:", forControlEvents: .TouchUpInside)
v.removeTarget(self, action: "handleCaptureButton:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleCaptureButton:", forControlEvents: .TouchUpInside)
} else {
captureButton?.removeFromSuperview()
captureButton = nil
......@@ -50,16 +50,16 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
/**
:name: flashAutoButton
:name: flashButton
*/
public var flashAutoButton: UIButton? {
public var flashButton: UIButton? {
didSet {
if let v: UIButton = flashAutoButton {
v.removeTarget(self, action: "handleFlashAuto:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleFlashAuto:", forControlEvents: .TouchUpInside)
if let v: UIButton = flashButton {
v.removeTarget(self, action: "handleFlashButton:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleFlashButton:", forControlEvents: .TouchUpInside)
} else {
flashAutoButton?.removeFromSuperview()
flashAutoButton = nil
flashButton?.removeFromSuperview()
flashButton = nil
}
}
}
......@@ -70,8 +70,8 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
public var switchCamerasButton: UIButton? {
didSet {
if let v: UIButton = switchCamerasButton {
v.removeTarget(self, action: "handleSwitchCamera:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleSwitchCamera:", forControlEvents: .TouchUpInside)
v.removeTarget(self, action: "handleSwitchCameraButton:", forControlEvents: .TouchUpInside)
v.addTarget(self, action: "handleSwitchCameraButton:", forControlEvents: .TouchUpInside)
} else {
switchCamerasButton?.removeFromSuperview()
switchCamerasButton = nil
......@@ -80,33 +80,6 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
/**
:name: switchCamerasButtonSize
*/
public var switchCamerasButtonSize: CGSize = CGSizeMake(48, 48) {
didSet {
reloadView()
}
}
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
didSet {
contentInsetsRef = MaterialEdgeInsetsToValue(contentInsets)
}
}
/**
:name: contentInsetsRef
*/
public var contentInsetsRef: UIEdgeInsets = MaterialTheme.basicCaptureView.contentInsetsRef {
didSet {
reloadView()
}
}
/**
:name: captureSession
*/
public var captureSession: CaptureSession {
......@@ -134,12 +107,7 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
:name: reloadView
*/
public func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview()
}
previewView.removeFromSuperview()
addSubview(previewView)
MaterialLayout.alignToParent(self, child: previewView)
}
......@@ -200,33 +168,35 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
/**
:name: handleCapture
:name: handleCaptureButton
*/
internal func handleCapture(button: UIButton) {
previewView.captureSession.captureStillImage()
internal func handleCaptureButton(button: UIButton) {
captureSession.captureStillImage()
}
/**
:name: handleSwitchCamera
:name: handleSwitchCameraButton
*/
internal func handleSwitchCamera(button: UIButton) {
previewView.captureSession.switchCameras()
internal func handleSwitchCameraButton(button: UIButton) {
captureSession.switchCameras()
}
/**
:name: handleFlashAuto
:name: handleFlashButton
*/
internal func handleFlashAuto(button: UIButton) {
switch previewView.captureSession.flashMode {
internal func handleFlashButton(button: UIButton) {
print(captureSession.flashMode == .Off)
switch captureSession.flashMode {
case .Off:
previewView.captureSession.flashMode = .On
captureSession.flashMode = .On
print("On")
case .On:
previewView.captureSession.flashMode = .Off
captureSession.flashMode = .Off
print("Auto")
case .Auto:
print("Off")
previewView.captureSession.flashMode = .On
captureSession.flashMode = .On
}
}
......
......@@ -24,7 +24,7 @@ public struct MaterialTheme {
public struct basicCardView {}
public struct imageCardView {}
public struct navigationBarView {}
public struct basicCaptureView {}
public struct captureView {}
public struct textLayer {}
public struct label {}
public struct flatButton {}
......@@ -205,15 +205,12 @@ public extension MaterialTheme.navigationBarView {
public static var zPosition: CGFloat = 100
}
// basicCaptureView
public extension MaterialTheme.basicCaptureView {
// captureView
public extension MaterialTheme.captureView {
// shadow
public static var shadowDepth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var contentInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square3)
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
......
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