Commit 30b1d92e by Daniel Dahan

updated CaptureView and example project.

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