Commit 37eec866 by Daniel Dahan

added tap focus, tap exposure, tap reset layers

parent 2685c8f6
......@@ -26,10 +26,9 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
lazy var closeButton: FlatButton = FlatButton()
lazy var cameraButton: FlatButton = FlatButton()
lazy var videoButton: FlatButton = FlatButton()
lazy var switchCameraButton: FlatButton = FlatButton()
lazy var switchCamerasButton: FlatButton = FlatButton()
lazy var flashButton: FlatButton = FlatButton()
lazy var captureButton: FabButton = FabButton()
lazy var captureMode: CaptureMode = .Video
override func viewDidLoad() {
super.viewDidLoad()
......@@ -38,15 +37,10 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
prepareCameraButton()
prepareVideoButton()
prepareCloseButton()
prepareSwitchCameraButton()
prepareSwitchCamerasButton()
prepareFlashButton()
prepareNavigationBarView()
prepareCaptureView()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
prepareNavigationBarView()
}
/**
......@@ -75,6 +69,13 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
func captureDidStartRecordingToOutputFileAtURL(capture: CaptureSession, captureOutput: AVCaptureFileOutput, fileURL: NSURL, fromConnections connections: [AnyObject]) {
print("Capture Started Recording \(fileURL)")
cameraButton.hidden = true
videoButton.hidden = true
switchCamerasButton.hidden = true
flashButton.hidden = true
navigationBarView.backgroundColor = nil
}
/**
......@@ -82,6 +83,13 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
func captureDidFinishRecordingToOutputFileAtURL(capture: CaptureSession, captureOutput: AVCaptureFileOutput, outputFileURL: NSURL, fromConnections connections: [AnyObject], error: NSError!) {
print("Capture Stopped Recording \(outputFileURL)")
cameraButton.hidden = false
videoButton.hidden = false
switchCamerasButton.hidden = false
flashButton.hidden = false
navigationBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.3)
}
/**
......@@ -91,7 +99,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
MaterialAnimation.animationDisabled {
self.navigationBarView.titleLabel!.text = String(format: "%02i:%02i:%02i", arguments: [hours, minutes, seconds])
}
}
/**
......@@ -127,117 +134,66 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
}
}
func captureViewDidPressFlashButton(captureView: CaptureView, button: UIButton) {
if .Back == captureView.captureSession.cameraPosition {
var img: UIImage?
switch captureView.captureSession.flashMode {
case .Off:
img = UIImage(named: "ic_flash_on_white")
captureView.captureSession.flashMode = .On
case .On:
img = UIImage(named: "ic_flash_auto_white")
captureView.captureSession.flashMode = .Auto
case .Auto:
img = UIImage(named: "ic_flash_off_white")
captureView.captureSession.flashMode = .Off
}
button.setImage(img, forState: .Normal)
button.setImage(img, forState: .Highlighted)
}
}
/**
:name: handleCameraButton
:name: captureViewDidPressCameraButton
*/
internal func handleCameraButton(button: UIButton) {
func captureViewDidPressCameraButton(captureView: CaptureView, button: UIButton) {
captureButton.backgroundColor = MaterialColor.blue.darken1.colorWithAlphaComponent(0.3)
captureMode = .Photo
}
/**
:name: handleVideoButton
:name: captureViewDidPressVideoButton
*/
internal func handleVideoButton(button: UIButton) {
func captureViewDidPressVideoButton(captureView: CaptureView, button: UIButton) {
captureButton.backgroundColor = MaterialColor.red.darken1.colorWithAlphaComponent(0.3)
captureMode = .Video
}
/**
:name: handleCaptureButton
:name: captureViewDidPressCaptureButton
*/
internal func handleCaptureButton(button: UIButton) {
if .Photo == captureMode {
captureView.captureSession.captureStillImage()
} else if .Video == captureMode {
if captureView.captureSession.isRecording {
captureView.captureSession.stopRecording()
captureView.stopTimer()
cameraButton.hidden = false
videoButton.hidden = false
if let v: Array<UIButton> = navigationBarView.leftButtons {
for x in v {
x.hidden = false
}
}
if let v: Array<UIButton> = navigationBarView.rightButtons {
for x in v {
x.hidden = false
}
}
navigationBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.3)
} else {
captureView.previewView.layer.addAnimation(MaterialAnimation.transition(.Fade), forKey: kCATransition)
captureView.captureSession.startRecording()
captureView.startTimer()
cameraButton.hidden = true
videoButton.hidden = true
if let v: Array<UIButton> = navigationBarView.leftButtons {
for x in v {
x.hidden = true
}
}
if let v: Array<UIButton> = navigationBarView.rightButtons {
for x in v {
x.hidden = true
}
}
navigationBarView.backgroundColor = nil
}
func captureViewDidPressCaptureButton(captureView: CaptureView, button: UIButton) {
if .Photo == captureView.captureMode {
// ... do something
} else if .Video == captureView.captureMode {
// ... do something
}
}
/**
:name: handleSwitchCameraButton
:name: captureViewDidPressSwitchCamerasButton
*/
internal func handleSwitchCameraButton(button: UIButton) {
func captureViewDidPressSwitchCamerasButton(captureView: CaptureView, button: UIButton) {
var img: UIImage?
captureView.previewView.layer.addAnimation(MaterialAnimation.transition(.Fade), forKey: kCATransition)
if .Back == captureView.captureSession.cameraPosition {
img = UIImage(named: "ic_camera_rear_white")
captureView.captureSession.switchCameras()
} else if .Front == captureView.captureSession.cameraPosition {
img = UIImage(named: "ic_camera_front_white")
captureView.captureSession.switchCameras()
} else if .Front == captureView.captureSession.cameraPosition {
img = UIImage(named: "ic_camera_rear_white")
}
switchCameraButton.setImage(img, forState: .Normal)
switchCameraButton.setImage(img, forState: .Highlighted)
}
/**
:name: handleFlashButton
*/
internal func handleFlashButton(button: UIButton) {
if .Back == captureView.captureSession.cameraPosition {
var img: UIImage?
switch captureView.captureSession.flashMode {
case .Off:
img = UIImage(named: "ic_flash_on_white")
captureView.captureSession.flashMode = .On
case .On:
img = UIImage(named: "ic_flash_auto_white")
captureView.captureSession.flashMode = .Auto
case .Auto:
img = UIImage(named: "ic_flash_off_white")
captureView.captureSession.flashMode = .Off
}
flashButton.setImage(img, forState: .Normal)
flashButton.setImage(img, forState: .Highlighted)
}
switchCamerasButton.setImage(img, forState: .Normal)
switchCamerasButton.setImage(img, forState: .Highlighted)
}
/**
......@@ -252,8 +208,11 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
private func prepareCaptureView() {
view.addSubview(captureView)
captureView.tapToFocusEnabled = true
captureView.tapToExposeEnabled = true
captureView.translatesAutoresizingMaskIntoConstraints = false
captureView.delegate = self
captureView.captureSession.delegate = self
MaterialLayout.alignToParent(view, child: captureView)
}
......@@ -283,7 +242,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
navigationBarView.detailLabel = detailLabel
navigationBarView.leftButtons = [closeButton]
navigationBarView.rightButtons = [switchCameraButton, flashButton]
navigationBarView.rightButtons = [switchCamerasButton, flashButton]
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
......@@ -304,8 +263,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
captureButton.borderWidth = .Border2
captureButton.borderColor = MaterialColor.white
captureButton.shadowDepth = .None
captureButton.addTarget(self, action: "handleCaptureButton:", forControlEvents: .TouchUpInside)
view.addSubview(captureButton)
captureView.captureButton = captureButton
}
......@@ -315,10 +272,11 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
private func prepareCameraButton() {
let img4: UIImage? = UIImage(named: "ic_photo_camera_white_36pt")
cameraButton.width = 72
cameraButton.height = 72
cameraButton.pulseColor = nil
cameraButton.setImage(img4, forState: .Normal)
cameraButton.setImage(img4, forState: .Highlighted)
cameraButton.addTarget(self, action: "handleCameraButton:", forControlEvents: .TouchUpInside)
captureView.cameraButton = cameraButton
}
......@@ -328,10 +286,11 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
private func prepareVideoButton() {
let img5: UIImage? = UIImage(named: "ic_videocam_white_36pt")
videoButton.width = 72
videoButton.height = 72
videoButton.pulseColor = nil
videoButton.setImage(img5, forState: .Normal)
videoButton.setImage(img5, forState: .Highlighted)
videoButton.addTarget(self, action: "handleVideoButton:", forControlEvents: .TouchUpInside)
captureView.videoButton = videoButton
}
......@@ -344,35 +303,30 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
closeButton.pulseColor = nil
closeButton.setImage(img, forState: .Normal)
closeButton.setImage(img, forState: .Highlighted)
captureView.closeButton = closeButton
}
/**
:name: prepareSwitchCameraButton
:name: prepareSwitchCamerasButton
*/
private func prepareSwitchCameraButton() {
private func prepareSwitchCamerasButton() {
let img: UIImage? = UIImage(named: "ic_camera_front_white")
switchCameraButton.pulseColor = nil
switchCameraButton.setImage(img, forState: .Normal)
switchCameraButton.setImage(img, forState: .Highlighted)
switchCameraButton.addTarget(self, action: "handleSwitchCameraButton:", forControlEvents: .TouchUpInside)
switchCamerasButton.pulseColor = nil
switchCamerasButton.setImage(img, forState: .Normal)
switchCamerasButton.setImage(img, forState: .Highlighted)
captureView.switchCameraButton = switchCameraButton
captureView.switchCamerasButton = switchCamerasButton
}
/**
:name: prepareFlashButton
*/
private func prepareFlashButton() {
captureView.captureSession.flashMode = .Auto
let img: UIImage? = UIImage(named: "ic_flash_auto_white")
flashButton.pulseColor = nil
flashButton.setImage(img, forState: .Normal)
flashButton.setImage(img, forState: .Highlighted)
flashButton.addTarget(self, action: "handleFlashButton:", forControlEvents: .TouchUpInside)
captureView.captureSession.flashMode = .Auto
captureView.flashButton = flashButton
}
}
......@@ -392,7 +392,7 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
/**
:name: switchCameras
*/
public func switchCameras() {
public func switchCameras(completion: ((success: Bool) -> Void)? = nil) {
if canSwitchCameras {
do {
self.delegate?.captureSessionWillSwitchCameras?(self, position: self.cameraPosition)
......@@ -407,8 +407,10 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
self.session.addInput(self.activeVideoInput)
}
self.session.commitConfiguration()
completion?(success: true)
self.delegate?.captureSessionDidSwitchCameras?(self, position: self.cameraPosition)
} catch let e as NSError {
completion?(success: false)
self.delegate?.captureSessionFailedWithError?(self, error: e)
}
}
......@@ -560,7 +562,7 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
:name: startRecording
*/
public func startRecording() {
if !self.isRecording {
if !isRecording {
dispatch_async(sessionQueue) {
let connection: AVCaptureConnection = self.movieOutput.connectionWithMediaType(AVMediaTypeVideo)
connection.videoOrientation = self.currentVideoOrientation
......
......@@ -55,6 +55,31 @@ public protocol CaptureViewDelegate : MaterialDelegate {
:name: captureViewDidTapToResetAtPoint
*/
optional func captureViewDidTapToResetAtPoint(captureView: CaptureView, point: CGPoint)
/**
:name: captureViewDidPressFlashButton
*/
optional func captureViewDidPressFlashButton(captureView: CaptureView, button: UIButton)
/**
:name: captureViewDidPressSwitchCamerasButton
*/
optional func captureViewDidPressSwitchCamerasButton(captureView: CaptureView, button: UIButton)
/**
:name: captureViewDidPressCaptureButton
*/
optional func captureViewDidPressCaptureButton(captureView: CaptureView, button: UIButton)
/**
:name: captureViewDidPressCameraButton
*/
optional func captureViewDidPressCameraButton(captureView: CaptureView, button: UIButton)
/**
:name: captureViewDidPressVideoButton
*/
optional func captureViewDidPressVideoButton(captureView: CaptureView, button: UIButton)
}
public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
......@@ -79,11 +104,52 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
private var tapToResetGesture: UITapGestureRecognizer?
/**
:name: tapToFocusEnabled
*/
public var tapToFocusEnabled: Bool = false {
didSet {
if tapToFocusEnabled {
tapToResetEnabled = true
prepareFocusLayer()
prepareTapGesture(&tapToFocusGesture, numberOfTapsRequired: 1, numberOfTouchesRequired: 1, selector: "handleTapToFocusGesture:")
if let v: UITapGestureRecognizer = tapToExposeGesture {
tapToFocusGesture!.requireGestureRecognizerToFail(v)
}
} else {
removeTapGesture(&tapToFocusGesture)
focusLayer?.removeFromSuperlayer()
focusLayer = nil
}
}
}
/**
:name: tapToExposeEnabled
*/
public var tapToExposeEnabled: Bool = false {
didSet {
if tapToExposeEnabled {
tapToResetEnabled = true
prepareExposureLayer()
prepareTapGesture(&tapToExposeGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 1, selector: "handleTapToExposeGesture:")
if let v: UITapGestureRecognizer = tapToFocusGesture {
v.requireGestureRecognizerToFail(tapToExposeGesture!)
}
} else {
removeTapGesture(&tapToExposeGesture)
exposureLayer?.removeFromSuperlayer()
exposureLayer = nil
}
}
}
/**
:name: tapToResetEnabled
*/
private var tapToResetEnabled: Bool = false {
didSet {
if tapToResetEnabled {
prepareResetLayer()
prepareTapGesture(&tapToResetGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 2, selector: "handleTapToResetGesture:")
if let v: UITapGestureRecognizer = tapToFocusGesture {
v.requireGestureRecognizerToFail(tapToResetGesture!)
......@@ -93,11 +159,18 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
}
} else {
removeTapGesture(&tapToResetGesture)
resetLayer?.removeFromSuperlayer()
resetLayer = nil
}
}
}
/**
:name: captureMode
*/
public private(set) lazy var captureMode: CaptureMode = .Video
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
......@@ -126,52 +199,28 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
public private(set) lazy var captureSession: CaptureSession = CaptureSession()
/**
:name: focusView
:name: focusLayer
*/
public var focusView: MaterialView? {
didSet {
if nil == focusView {
removeTapGesture(&tapToFocusGesture)
} else {
tapToResetEnabled = true
prepareFocusView()
prepareTapGesture(&tapToFocusGesture, numberOfTapsRequired: 1, numberOfTouchesRequired: 1, selector: "handleTapToFocusGesture:")
if let v: UITapGestureRecognizer = tapToExposeGesture {
tapToFocusGesture!.requireGestureRecognizerToFail(v)
}
}
}
}
public private(set) var focusLayer: MaterialLayer?
/**
:name: exposureView
:name: exposureLayer
*/
public var exposureView: MaterialView? {
didSet {
if nil == exposureView {
removeTapGesture(&tapToExposeGesture)
} else {
tapToResetEnabled = true
prepareExposureView()
prepareTapGesture(&tapToExposeGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 1, selector: "handleTapToExposeGesture:")
if let v: UITapGestureRecognizer = tapToFocusGesture {
v.requireGestureRecognizerToFail(tapToExposeGesture!)
}
}
}
}
public private(set) var exposureLayer: MaterialLayer?
/**
:name: closeButton
:name: resetLayer
*/
public var closeButton: MaterialButton?
public private(set) var resetLayer: MaterialLayer?
/**
:name: cameraButton
*/
public var cameraButton: MaterialButton? {
public var cameraButton: UIButton? {
didSet {
cameraButton?.translatesAutoresizingMaskIntoConstraints = false
if let v: UIButton = cameraButton {
v.addTarget(self, action: "handleCameraButton:", forControlEvents: .TouchUpInside)
}
reloadView()
}
}
......@@ -179,27 +228,49 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: captureButton
*/
public var captureButton: MaterialButton?
public var captureButton: UIButton? {
didSet {
if let v: UIButton = captureButton {
v.addTarget(self, action: "handleCaptureButton:", forControlEvents: .TouchUpInside)
}
reloadView()
}
}
/**
:name: videoButton
*/
public var videoButton: MaterialButton? {
public var videoButton: UIButton? {
didSet {
videoButton?.translatesAutoresizingMaskIntoConstraints = false
if let v: UIButton = videoButton {
v.addTarget(self, action: "handleVideoButton:", forControlEvents: .TouchUpInside)
}
reloadView()
}
}
/**
:name: switchCameraButton
:name: switchCamerasButton
*/
public var switchCameraButton: MaterialButton?
public var switchCamerasButton: UIButton? {
didSet {
if let v: UIButton = switchCamerasButton {
v.addTarget(self, action: "handleSwitchCamerasButton:", forControlEvents: .TouchUpInside)
}
}
}
/**
:name: flashButton
*/
public var flashButton: MaterialButton?
public var flashButton: UIButton? {
didSet {
if let v: UIButton = flashButton {
v.addTarget(self, action: "handleFlashButton:", forControlEvents: .TouchUpInside)
}
}
}
/**
:name: init
......@@ -213,9 +284,17 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
*/
public override func layoutSubviews() {
super.layoutSubviews()
if let v: MaterialButton = captureButton {
v.y = bounds.height - contentInsetsRef.bottom - v.height
v.x = (bounds.width - v.width) / 2
if let v: UIButton = cameraButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.x = contentInsetsRef.left
}
if let v: UIButton = captureButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.x = (bounds.width - v.bounds.width) / 2
}
if let v: UIButton = videoButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.x = bounds.width - v.bounds.width - contentInsetsRef.right
}
(previewView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation = captureSession.currentVideoOrientation
}
......@@ -254,21 +333,23 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
addSubview(previewView)
MaterialLayout.alignToParent(self, child: previewView)
if let v: MaterialButton = cameraButton {
if let v: UIButton = captureButton {
addSubview(v)
}
if let v: UIButton = cameraButton {
addSubview(v)
MaterialLayout.alignFromBottomLeft(self, child: v, bottom: contentInsetsRef.bottom, left: contentInsetsRef.left)
}
if let v: MaterialButton = videoButton {
if let v: UIButton = videoButton {
addSubview(v)
MaterialLayout.alignFromBottomRight(self, child: v, bottom: contentInsetsRef.bottom, right: contentInsetsRef.right)
}
}
/**
:name: startTimer
*/
public func startTimer() {
internal func startTimer() {
timer?.invalidate()
timer = NSTimer(timeInterval: 0.5, target: self, selector: "updateTimer", userInfo: nil, repeats: true)
NSRunLoop.mainRunLoop().addTimer(timer!, forMode: NSRunLoopCommonModes)
......@@ -278,7 +359,7 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: updateTimer
*/
public func updateTimer() {
internal func updateTimer() {
let duration: CMTime = captureSession.recordedDuration
let time: Double = CMTimeGetSeconds(duration)
let hours: Int = Int(time / 3600)
......@@ -290,7 +371,7 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: stopTimer
*/
public func stopTimer() {
internal func stopTimer() {
let duration: CMTime = captureSession.recordedDuration
let time: Double = CMTimeGetSeconds(duration)
let hours: Int = Int(time / 3600)
......@@ -302,29 +383,66 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
}
/**
:name: handleFlashButton
*/
internal func handleFlashButton(button: UIButton) {
(delegate as? CaptureViewDelegate)?.captureViewDidPressFlashButton?(self, button: button)
}
/**
:name: handleSwitchCamerasButton
*/
internal func handleSwitchCamerasButton(button: UIButton) {
previewView.layer.addAnimation(MaterialAnimation.transition(.Fade), forKey: kCATransition)
captureSession.switchCameras { (success: Bool) in
(self.delegate as? CaptureViewDelegate)?.captureViewDidPressSwitchCamerasButton?(self, button: button)
}
}
/**
:name: handleCaptureButton
*/
internal func handleCaptureButton(button: UIButton) {
if .Photo == captureMode {
captureSession.captureStillImage()
} else if .Video == captureMode {
if captureSession.isRecording {
captureSession.stopRecording()
stopTimer()
} else {
previewView.layer.addAnimation(MaterialAnimation.transition(.Fade), forKey: kCATransition)
captureSession.startRecording()
startTimer()
}
}
(delegate as? CaptureViewDelegate)?.captureViewDidPressCaptureButton?(self, button: button)
}
/**
:name: handleCameraButton
*/
internal func handleCameraButton(button: UIButton) {
captureMode = .Photo
(delegate as? CaptureViewDelegate)?.captureViewDidPressCameraButton?(self, button: button)
}
/**
:name: handleVideoButton
*/
internal func handleVideoButton(button: UIButton) {
captureMode = .Video
(delegate as? CaptureViewDelegate)?.captureViewDidPressVideoButton?(self, button: button)
}
/**
:name: handleTapToFocusGesture
*/
internal func handleTapToFocusGesture(recognizer: UITapGestureRecognizer) {
if let v: MaterialView = focusView {
if captureSession.cameraSupportsTapToFocus {
let point: CGPoint = recognizer.locationInView(self)
captureSession.focusAtPoint(previewView.captureDevicePointOfInterestForPoint(point))
MaterialAnimation.animationDisabled {
v.layer.transform = CATransform3DIdentity
v.position = point
v.hidden = false
}
MaterialAnimation.animateWithDuration(0.25, animations: {
v.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1)
}) {
MaterialAnimation.delay(0.4) {
MaterialAnimation.animationDisabled {
v.hidden = true
}
}
}
(delegate as? CaptureViewDelegate)?.captureViewDidTapToFocusAtPoint?(self, point: point)
}
if tapToFocusEnabled && captureSession.cameraSupportsTapToFocus {
let point: CGPoint = recognizer.locationInView(self)
captureSession.focusAtPoint(previewView.captureDevicePointOfInterestForPoint(point))
animateTapLayer(layer: focusLayer!, point: point)
(delegate as? CaptureViewDelegate)?.captureViewDidTapToFocusAtPoint?(self, point: point)
}
}
......@@ -332,9 +450,10 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
:name: handleTapToExposeGesture
*/
internal func handleTapToExposeGesture(recognizer: UITapGestureRecognizer) {
if nil != exposureView && captureSession.cameraSupportsTapToExpose {
if tapToExposeEnabled && captureSession.cameraSupportsTapToExpose {
let point: CGPoint = recognizer.locationInView(self)
captureSession.exposeAtPoint(previewView.captureDevicePointOfInterestForPoint(point))
animateTapLayer(layer: exposureLayer!, point: point)
(delegate as? CaptureViewDelegate)?.captureViewDidTapToExposeAtPoint?(self, point: point)
}
}
......@@ -346,6 +465,7 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
if tapToResetEnabled {
captureSession.resetFocusAndExposureModes()
let point: CGPoint = previewView.pointForCaptureDevicePointOfInterest(CGPointMake(0.5, 0.5))
animateTapLayer(layer: resetLayer!, point: point)
(delegate as? CaptureViewDelegate)?.captureViewDidTapToResetAtPoint?(self, point: point)
}
}
......@@ -382,20 +502,61 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
}
/**
:name: prepareFocusView
:name: prepareFocusLayer
*/
private func prepareFocusLayer() {
if nil == focusLayer {
focusLayer = MaterialLayer(frame: CGRectMake(0, 0, 150, 150))
focusLayer!.hidden = true
focusLayer!.borderWidth = 2
focusLayer!.borderColor = MaterialColor.white.CGColor
previewView.layer.addSublayer(focusLayer!)
}
}
/**
:name: prepareExposureLayer
*/
private func prepareExposureLayer() {
if nil == exposureLayer {
exposureLayer = MaterialLayer(frame: CGRectMake(0, 0, 150, 150))
exposureLayer!.hidden = true
exposureLayer!.borderWidth = 2
exposureLayer!.borderColor = MaterialColor.yellow.darken1.CGColor
previewView.layer.addSublayer(exposureLayer!)
}
}
/**
:name: prepareResetLayer
*/
private func prepareFocusView() {
if let v: MaterialView = focusView {
v.hidden = true
private func prepareResetLayer() {
if nil == resetLayer {
resetLayer = MaterialLayer(frame: CGRectMake(0, 0, 150, 150))
resetLayer!.hidden = true
resetLayer!.borderWidth = 2
resetLayer!.borderColor = MaterialColor.purple.darken1.CGColor
previewView.layer.addSublayer(resetLayer!)
}
}
/**
:name: prepareExposureView
:name: animateTapLayer
*/
private func prepareExposureView() {
if let v: MaterialView = exposureView {
v.hidden = true
private func animateTapLayer(layer v: MaterialLayer, point: CGPoint) {
MaterialAnimation.animationDisabled {
v.transform = CATransform3DIdentity
v.position = point
v.hidden = false
}
MaterialAnimation.animateWithDuration(0.25, animations: {
v.transform = CATransform3DMakeScale(0.5, 0.5, 1)
}) {
MaterialAnimation.delay(0.4) {
MaterialAnimation.animationDisabled {
v.hidden = true
}
}
}
}
}
\ No newline at end of file
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