Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
124ec56c
Unverified
Commit
124ec56c
authored
Oct 30, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added updates to CaptureDelgate organization
parent
321d15fb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
467 additions
and
446 deletions
+467
-446
Sources/iOS/Capture/Capture.swift
+417
-1
Sources/iOS/Capture/CaptureController.swift
+3
-424
Sources/iOS/Capture/CaptureSession.swift
+31
-18
Sources/iOS/NavigationDrawerController.swift
+0
-3
Sources/iOS/RootController.swift
+10
-0
Sources/iOS/StatusBarController.swift
+6
-0
No files found.
Sources/iOS/Capture/Capture.swift
View file @
124ec56c
...
...
@@ -37,16 +37,224 @@ public enum CaptureMode: Int {
case
video
}
open
class
Capture
:
View
{
@objc(CaptureDelegate)
public
protocol
CaptureDelegate
{
/**
A delegation method that is fired when the record timer has started.
- Parameter capture: A reference to the calling capture.
*/
@objc
optional
func
captureDidStartRecordTimer
(
capture
:
Capture
)
/**
A delegation method that is fired when the record timer was updated.
- Parameter capture: A reference to the calling capture.
- Parameter hours: An integer representing hours.
- Parameter minutes: An integer representing minutes.
- Parameter seconds: An integer representing seconds.
*/
@objc
optional
func
captureDidUpdateRecordTimer
(
capture
:
Capture
,
hours
:
Int
,
minutes
:
Int
,
seconds
:
Int
)
/**
A delegation method that is fired when the record timer has stopped.
- Parameter capture: A reference to the calling capture.
- Parameter hours: An integer representing hours.
- Parameter minutes: An integer representing minutes.
- Parameter seconds: An integer representing seconds.
*/
@objc
optional
func
captureDidStopRecordTimer
(
capture
:
Capture
,
hours
:
Int
,
minutes
:
Int
,
seconds
:
Int
)
/**
A delegation method that is fired when the user tapped to adjust the focus.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToFocusAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user tapped to adjust the exposure.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToExposeAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user tapped to reset.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToResetAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user pressed the flash button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressFlashButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user pressed the switch camera button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressSwitchCamerasButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user pressed capture button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressCaptureButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user enabled the photo camera.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressCameraButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user enabled the video camera.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressVideoButton
(
capture
:
Capture
,
button
:
UIButton
)
}
open
class
Capture
:
View
,
UIGestureRecognizerDelegate
{
/// A reference to the capture mode.
open
var
mode
=
CaptureMode
.
video
/// Delegation handler.
open
weak
var
delegate
:
CaptureDelegate
?
/// A reference to the CapturePreview view.
open
internal(set)
var
preview
:
CapturePreview
!
/// A reference to the CaptureSession.
open
internal(set)
var
session
:
CaptureSession
!
/// A Timer reference for when recording is enabled.
internal
var
timer
:
Timer
?
/// A tap gesture reference for focus events.
private
var
tapToFocusGesture
:
UITapGestureRecognizer
?
/// A tap gesture reference for exposure events.
private
var
tapToExposeGesture
:
UITapGestureRecognizer
?
/// A tap gesture reference for reset events.
private
var
tapToResetGesture
:
UITapGestureRecognizer
?
/// A reference to the captureButton.
@IBInspectable
open
var
captureButton
:
UIButton
?
{
didSet
{
prepareCaptureButton
()
}
}
/// A reference to the cameraButton.
@IBInspectable
open
var
cameraButton
:
UIButton
?
{
didSet
{
prepareCameraButton
()
}
}
/// A reference to the videoButton.
@IBInspectable
open
var
videoButton
:
UIButton
?
{
didSet
{
prepareVideoButton
()
}
}
/// A reference to the switchCameraButton.
@IBInspectable
open
var
switchCamerasButton
:
UIButton
?
{
didSet
{
prepareSwitchCamerasButton
()
}
}
/// A reference to the flashButton.
@IBInspectable
open
var
flashButton
:
UIButton
?
{
didSet
{
prepareFlashButton
()
}
}
/// A boolean indicating whether to enable tap to focus.
@IBInspectable
open
var
isTapToFocusEnabled
=
false
{
didSet
{
guard
isTapToFocusEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToFocusGesture
)
return
}
isTapToResetEnabled
=
true
prepareTapGesture
(
gesture
:
&
tapToFocusGesture
,
numberOfTapsRequired
:
1
,
numberOfTouchesRequired
:
1
,
selector
:
#selector(
handleTapToFocusGesture
)
)
if
let
v
=
tapToExposeGesture
{
tapToFocusGesture
!.
require
(
toFail
:
v
)
}
}
}
/// A boolean indicating whether to enable tap to expose.
@IBInspectable
open
var
isTapToExposeEnabled
=
false
{
didSet
{
guard
isTapToExposeEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToExposeGesture
)
return
}
isTapToResetEnabled
=
true
prepareTapGesture
(
gesture
:
&
tapToExposeGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
1
,
selector
:
#selector(
handleTapToExposeGesture
)
)
if
let
v
=
tapToFocusGesture
{
v
.
require
(
toFail
:
tapToExposeGesture
!
)
}
}
}
/// A boolean indicating whether to enable tap to reset.
@IBInspectable
open
var
isTapToResetEnabled
=
false
{
didSet
{
guard
isTapToResetEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToResetGesture
)
return
}
prepareTapGesture
(
gesture
:
&
tapToResetGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
2
,
selector
:
#selector(
handleTapToResetGesture
)
)
if
let
v
=
tapToFocusGesture
{
v
.
require
(
toFail
:
tapToResetGesture
!
)
}
if
let
v
=
tapToExposeGesture
{
v
.
require
(
toFail
:
tapToResetGesture
!
)
}
}
}
/// A convenience initializer.
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
...
...
@@ -70,6 +278,9 @@ open class Capture: View {
prepareCaptureSession
()
preparePreview
()
isTapToFocusEnabled
=
true
isTapToExposeEnabled
=
true
}
/// Reloads the view.
...
...
@@ -90,4 +301,209 @@ open class Capture: View {
(
preview
.
layer
as!
AVCaptureVideoPreviewLayer
)
.
session
=
session
.
session
session
.
startSession
()
}
/// Prepares the captureButton.
private
func
prepareCaptureButton
()
{
captureButton
?
.
addTarget
(
self
,
action
:
#selector(
handleCaptureButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the cameraButton.
private
func
prepareCameraButton
()
{
cameraButton
?
.
addTarget
(
self
,
action
:
#selector(
handleCameraButton
)
,
for
:
.
touchUpInside
)
}
/// Preapres the videoButton.
private
func
prepareVideoButton
()
{
videoButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVideoButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the switchCameraButton.
private
func
prepareSwitchCamerasButton
()
{
switchCamerasButton
?
.
addTarget
(
self
,
action
:
#selector(
handleSwitchCamerasButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the flashButton.
private
func
prepareFlashButton
()
{
flashButton
?
.
addTarget
(
self
,
action
:
#selector(
handleFlashButton
)
,
for
:
.
touchUpInside
)
}
/**
Prepares a given tap gesture.
- Parameter gesture: An optional UITapGestureRecognizer to prepare.
- Parameter numberOfTapsRequired: An integer of the number of taps required
to activate the gesture.
- Parameter numberOfTouchesRequired: An integer of the number of touches, fingers,
required to activate the gesture.
- Parameter selector: A Selector to handle the event.
*/
private
func
prepareTapGesture
(
gesture
:
inout
UITapGestureRecognizer
?,
numberOfTapsRequired
:
Int
,
numberOfTouchesRequired
:
Int
,
selector
:
Selector
)
{
guard
nil
==
gesture
else
{
return
}
gesture
=
UITapGestureRecognizer
(
target
:
self
,
action
:
selector
)
gesture
!.
delegate
=
self
gesture
!.
numberOfTapsRequired
=
numberOfTapsRequired
gesture
!.
numberOfTouchesRequired
=
numberOfTouchesRequired
addGestureRecognizer
(
gesture
!
)
}
/**
Removes a given tap gesture.
- Parameter gesture: An optional UITapGestureRecognizer to remove.
*/
private
func
removeTapGesture
(
gesture
:
inout
UITapGestureRecognizer
?)
{
guard
let
v
=
gesture
else
{
return
}
removeGestureRecognizer
(
v
)
gesture
=
nil
}
}
extension
Capture
{
/**
Handler for the captureButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleCaptureButton
(
button
:
UIButton
)
{
switch
mode
{
case
.
photo
:
session
.
captureStillImage
()
case
.
video
:
if
session
.
isRecording
{
session
.
stopRecording
()
stopTimer
()
}
else
{
session
.
startRecording
()
startTimer
()
}
}
delegate
?
.
captureDidPressCaptureButton
?(
capture
:
self
,
button
:
button
)
}
/**
Handler for the cameraButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleCameraButton
(
button
:
UIButton
)
{
mode
=
.
photo
delegate
?
.
captureDidPressCameraButton
?(
capture
:
self
,
button
:
button
)
}
/**
Handler for the flashButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleFlashButton
(
button
:
UIButton
)
{
delegate
?
.
captureDidPressFlashButton
?(
capture
:
self
,
button
:
button
)
}
/**
Handler for the switchCameraButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleSwitchCamerasButton
(
button
:
UIButton
)
{
session
.
switchCameras
()
delegate
?
.
captureDidPressSwitchCamerasButton
?(
capture
:
self
,
button
:
button
)
}
/**
Handler for the videoButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleVideoButton
(
button
:
UIButton
)
{
mode
=
.
video
delegate
?
.
captureDidPressVideoButton
?(
capture
:
self
,
button
:
button
)
}
/**
Handler for the tapToFocusGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToFocusGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToFocusEnabled
&&
session
.
isFocusPointOfInterestSupported
else
{
return
}
let
point
=
recognizer
.
location
(
in
:
self
)
session
.
focus
(
at
:
preview
.
captureDevicePointOfInterestForPoint
(
point
:
point
))
delegate
?
.
captureDidTapToFocusAtPoint
?(
capture
:
self
,
point
:
point
)
}
/**
Handler for the tapToExposeGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToExposeGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToExposeEnabled
&&
session
.
isExposurePointOfInterestSupported
else
{
return
}
let
point
=
recognizer
.
location
(
in
:
self
)
session
.
expose
(
at
:
preview
.
captureDevicePointOfInterestForPoint
(
point
:
point
))
delegate
?
.
captureDidTapToExposeAtPoint
?(
capture
:
self
,
point
:
point
)
}
/**
Handler for the tapToResetGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToResetGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToResetEnabled
else
{
return
}
session
.
reset
()
let
point
=
preview
.
pointForCaptureDevicePointOfInterest
(
point
:
CGPoint
(
x
:
0.5
,
y
:
0.5
))
delegate
?
.
captureDidTapToResetAtPoint
?(
capture
:
self
,
point
:
point
)
}
}
extension
Capture
{
/// Starts the timer for recording.
internal
func
startTimer
()
{
timer
?
.
invalidate
()
timer
=
Timer
(
timeInterval
:
0.5
,
target
:
self
,
selector
:
#selector(
updateTimer
)
,
userInfo
:
nil
,
repeats
:
true
)
RunLoop
.
main
.
add
(
timer
!
,
forMode
:
.
commonModes
)
delegate
?
.
captureDidStartRecordTimer
?(
capture
:
self
)
}
/// Updates the timer when recording.
internal
func
updateTimer
()
{
let
duration
=
session
.
recordedDuration
let
time
=
CMTimeGetSeconds
(
duration
)
let
hours
=
Int
(
time
/
3600
)
let
minutes
=
Int
((
time
/
60
)
.
truncatingRemainder
(
dividingBy
:
60
))
let
seconds
=
Int
(
time
.
truncatingRemainder
(
dividingBy
:
60
))
delegate
?
.
captureDidUpdateRecordTimer
?(
capture
:
self
,
hours
:
hours
,
minutes
:
minutes
,
seconds
:
seconds
)
}
/// Stops the timer when recording.
internal
func
stopTimer
()
{
let
duration
=
session
.
recordedDuration
let
time
=
CMTimeGetSeconds
(
duration
)
let
hours
=
Int
(
time
/
3600
)
let
minutes
=
Int
((
time
/
60
)
.
truncatingRemainder
(
dividingBy
:
60
))
let
seconds
=
Int
(
time
.
truncatingRemainder
(
dividingBy
:
60
))
timer
?
.
invalidate
()
timer
=
nil
delegate
?
.
captureDidStopRecordTimer
?(
capture
:
self
,
hours
:
hours
,
minutes
:
minutes
,
seconds
:
seconds
)
}
}
Sources/iOS/Capture/CaptureController.swift
View file @
124ec56c
...
...
@@ -49,214 +49,10 @@ extension UIViewController {
}
}
@objc(CaptureControllerDelegate)
public
protocol
CaptureControllerDelegate
:
ToolbarControllerDelegate
{
/**
A delegation method that is fired when the record timer has started.
- Parameter capture: A reference to the calling capture.
*/
@objc
optional
func
captureDidStartRecordTimer
(
capture
:
Capture
)
/**
A delegation method that is fired when the record timer was updated.
- Parameter capture: A reference to the calling capture.
- Parameter hours: An integer representing hours.
- Parameter minutes: An integer representing minutes.
- Parameter seconds: An integer representing seconds.
*/
@objc
optional
func
captureDidUpdateRecordTimer
(
capture
:
Capture
,
hours
:
Int
,
minutes
:
Int
,
seconds
:
Int
)
/**
A delegation method that is fired when the record timer has stopped.
- Parameter capture: A reference to the calling capture.
- Parameter hours: An integer representing hours.
- Parameter minutes: An integer representing minutes.
- Parameter seconds: An integer representing seconds.
*/
@objc
optional
func
captureDidStopRecordTimer
(
capture
:
Capture
,
hours
:
Int
,
minutes
:
Int
,
seconds
:
Int
)
/**
A delegation method that is fired when the user tapped to adjust the focus.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToFocusAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user tapped to adjust the exposure.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToExposeAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user tapped to reset.
- Parameter capture: A reference to the calling capture.
- Parameter point: CGPoint that the user tapped at.
*/
@objc
optional
func
captureDidTapToResetAtPoint
(
capture
:
Capture
,
point
:
CGPoint
)
/**
A delegation method that is fired when the user pressed the flash button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressFlashButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user pressed the switch camera button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressSwitchCamerasButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user pressed capture button.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressCaptureButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user enabled the photo camera.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressCameraButton
(
capture
:
Capture
,
button
:
UIButton
)
/**
A delegation method that is fired when the user enabled the video camera.
- Parameter capture: A reference to the calling capture.
- Parameter button: A reference to the UIButton that the user pressed.
*/
@objc
optional
func
captureDidPressVideoButton
(
capture
:
Capture
,
button
:
UIButton
)
}
open
class
CaptureController
:
ToolbarController
,
CaptureControllerDelegate
,
CaptureSessionDelegate
,
UIGestureRecognizerDelegate
{
open
class
CaptureController
:
ToolbarController
,
CaptureDelegate
,
CaptureSessionDelegate
{
/// A reference to the Capture instance.
open
private(set)
lazy
var
capture
:
Capture
=
Capture
()
/// A Timer reference for when recording is enabled.
internal
var
timer
:
Timer
?
/// A tap gesture reference for focus events.
private
var
tapToFocusGesture
:
UITapGestureRecognizer
?
/// A tap gesture reference for exposure events.
private
var
tapToExposeGesture
:
UITapGestureRecognizer
?
/// A tap gesture reference for reset events.
private
var
tapToResetGesture
:
UITapGestureRecognizer
?
/// A reference to the cameraButton.
open
private(set)
var
cameraButton
:
IconButton
!
/// A reference to the captureButton.
open
private(set)
var
captureButton
:
FabButton
!
/// A reference to the videoButton.
open
private(set)
var
videoButton
:
IconButton
!
/// A reference to the switchCameraButton.
open
private(set)
var
switchCamerasButton
:
IconButton
!
/// A reference to the flashButton.
open
private(set)
var
flashButton
:
IconButton
!
/// A boolean indicating whether to enable tap to focus.
@IBInspectable
open
var
isTapToFocusEnabled
=
false
{
didSet
{
guard
isTapToFocusEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToFocusGesture
)
return
}
isTapToResetEnabled
=
true
prepareTapGesture
(
gesture
:
&
tapToFocusGesture
,
numberOfTapsRequired
:
1
,
numberOfTouchesRequired
:
1
,
selector
:
#selector(
handleTapToFocusGesture
)
)
if
let
v
=
tapToExposeGesture
{
tapToFocusGesture
!.
require
(
toFail
:
v
)
}
}
}
/// A boolean indicating whether to enable tap to expose.
@IBInspectable
open
var
isTapToExposeEnabled
=
false
{
didSet
{
guard
isTapToExposeEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToExposeGesture
)
return
}
isTapToResetEnabled
=
true
prepareTapGesture
(
gesture
:
&
tapToExposeGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
1
,
selector
:
#selector(
handleTapToExposeGesture
)
)
if
let
v
=
tapToFocusGesture
{
v
.
require
(
toFail
:
tapToExposeGesture
!
)
}
}
}
/// A boolean indicating whether to enable tap to reset.
@IBInspectable
open
var
isTapToResetEnabled
=
false
{
didSet
{
guard
isTapToResetEnabled
else
{
removeTapGesture
(
gesture
:
&
tapToResetGesture
)
return
}
prepareTapGesture
(
gesture
:
&
tapToResetGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
2
,
selector
:
#selector(
handleTapToResetGesture
)
)
if
let
v
=
tapToFocusGesture
{
v
.
require
(
toFail
:
tapToResetGesture
!
)
}
if
let
v
=
tapToExposeGesture
{
v
.
require
(
toFail
:
tapToResetGesture
!
)
}
}
}
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
/**
if let v = cameraButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = contentEdgeInsets.left
}
if let v = captureButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = (bounds.width - v.width) / 2
}
if let v = videoButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = bounds.width - v.width - contentEdgeInsets.right
}
if let v = (preview.layer as! AVCaptureVideoPreviewLayer).connection {
v.videoOrientation = session.videoOrientation
}
*/
}
open
private(set)
lazy
var
capture
:
Capture
=
Capture
()
/**
Prepares the view instance when intialized. When subclassing,
...
...
@@ -268,19 +64,11 @@ open class CaptureController: ToolbarController, CaptureControllerDelegate, Capt
open
override
func
prepare
()
{
super
.
prepare
()
display
=
.
full
delegate
=
self
view
.
backgroundColor
=
.
black
isTapToFocusEnabled
=
true
isTapToExposeEnabled
=
true
prepareStatusBar
()
prepareToolbar
()
prepareCapture
()
prepareCaptureButton
()
prepareCameraButton
()
prepareVideoButton
()
prepareSwitchCamerasButton
()
prepareFlashButton
()
}
/// Prepares the statusBar.
...
...
@@ -296,217 +84,8 @@ open class CaptureController: ToolbarController, CaptureControllerDelegate, Capt
/// Prepares capture.
private
func
prepareCapture
()
{
capture
.
delegate
=
self
capture
.
session
.
delegate
=
self
}
/// Prepares the captureButton.
private
func
prepareCaptureButton
()
{
captureButton
=
FabButton
()
captureButton
.
addTarget
(
self
,
action
:
#selector(
handleCaptureButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the cameraButton.
private
func
prepareCameraButton
()
{
cameraButton
=
IconButton
(
image
:
Icon
.
cm
.
photoCamera
,
tintColor
:
.
white
)
cameraButton
.
addTarget
(
self
,
action
:
#selector(
handleCameraButton
)
,
for
:
.
touchUpInside
)
}
/// Preapres the videoButton.
private
func
prepareVideoButton
()
{
videoButton
=
IconButton
(
image
:
Icon
.
cm
.
videocam
,
tintColor
:
.
white
)
videoButton
.
addTarget
(
self
,
action
:
#selector(
handleVideoButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the switchCameraButton.
private
func
prepareSwitchCamerasButton
()
{
switchCamerasButton
=
IconButton
(
image
:
Icon
.
cameraFront
,
tintColor
:
.
white
)
switchCamerasButton
.
addTarget
(
self
,
action
:
#selector(
handleSwitchCamerasButton
)
,
for
:
.
touchUpInside
)
}
/// Prepares the flashButton.
private
func
prepareFlashButton
()
{
flashButton
=
IconButton
(
image
:
Icon
.
flashAuto
,
tintColor
:
.
white
)
flashButton
.
addTarget
(
self
,
action
:
#selector(
handleFlashButton
)
,
for
:
.
touchUpInside
)
capture
.
session
.
flashMode
=
.
auto
}
/**
Prepares a given tap gesture.
- Parameter gesture: An optional UITapGestureRecognizer to prepare.
- Parameter numberOfTapsRequired: An integer of the number of taps required
to activate the gesture.
- Parameter numberOfTouchesRequired: An integer of the number of touches, fingers,
required to activate the gesture.
- Parameter selector: A Selector to handle the event.
*/
private
func
prepareTapGesture
(
gesture
:
inout
UITapGestureRecognizer
?,
numberOfTapsRequired
:
Int
,
numberOfTouchesRequired
:
Int
,
selector
:
Selector
)
{
guard
nil
==
gesture
else
{
return
}
gesture
=
UITapGestureRecognizer
(
target
:
self
,
action
:
selector
)
gesture
!.
delegate
=
self
gesture
!.
numberOfTapsRequired
=
numberOfTapsRequired
gesture
!.
numberOfTouchesRequired
=
numberOfTouchesRequired
view
.
addGestureRecognizer
(
gesture
!
)
}
/**
Removes a given tap gesture.
- Parameter gesture: An optional UITapGestureRecognizer to remove.
*/
private
func
removeTapGesture
(
gesture
:
inout
UITapGestureRecognizer
?)
{
guard
let
v
=
gesture
else
{
return
}
view
.
removeGestureRecognizer
(
v
)
gesture
=
nil
}
}
extension
CaptureController
{
/**
Handler for the captureButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleCaptureButton
(
button
:
UIButton
)
{
switch
capture
.
mode
{
case
.
photo
:
capture
.
session
.
captureStillImage
()
case
.
video
:
if
capture
.
session
.
isRecording
{
capture
.
session
.
stopRecording
()
stopTimer
()
}
else
{
capture
.
session
.
startRecording
()
startTimer
()
}
}
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidPressCaptureButton
?(
capture
:
capture
,
button
:
button
)
}
/**
Handler for the cameraButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleCameraButton
(
button
:
UIButton
)
{
capture
.
mode
=
.
photo
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidPressCameraButton
?(
capture
:
capture
,
button
:
button
)
}
/**
Handler for the flashButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleFlashButton
(
button
:
UIButton
)
{
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidPressFlashButton
?(
capture
:
capture
,
button
:
button
)
}
/**
Handler for the switchCameraButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleSwitchCamerasButton
(
button
:
UIButton
)
{
capture
.
session
.
switchCameras
()
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidPressSwitchCamerasButton
?(
capture
:
capture
,
button
:
button
)
}
/**
Handler for the videoButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal
func
handleVideoButton
(
button
:
UIButton
)
{
capture
.
mode
=
.
video
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidPressVideoButton
?(
capture
:
capture
,
button
:
button
)
}
/**
Handler for the tapToFocusGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToFocusGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToFocusEnabled
&&
capture
.
session
.
isFocusPointOfInterestSupported
else
{
return
}
let
point
=
recognizer
.
location
(
in
:
view
)
capture
.
session
.
focus
(
at
:
capture
.
preview
.
captureDevicePointOfInterestForPoint
(
point
:
point
))
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidTapToFocusAtPoint
?(
capture
:
capture
,
point
:
point
)
}
/**
Handler for the tapToExposeGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToExposeGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToExposeEnabled
&&
capture
.
session
.
isExposurePointOfInterestSupported
else
{
return
}
let
point
=
recognizer
.
location
(
in
:
view
)
capture
.
session
.
expose
(
at
:
capture
.
preview
.
captureDevicePointOfInterestForPoint
(
point
:
point
))
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidTapToExposeAtPoint
?(
capture
:
capture
,
point
:
point
)
}
/**
Handler for the tapToResetGesture.
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/
@objc
internal
func
handleTapToResetGesture
(
recognizer
:
UITapGestureRecognizer
)
{
guard
isTapToResetEnabled
else
{
return
}
capture
.
session
.
reset
()
let
point
=
capture
.
preview
.
pointForCaptureDevicePointOfInterest
(
point
:
CGPoint
(
x
:
0.5
,
y
:
0.5
))
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidTapToResetAtPoint
?(
capture
:
capture
,
point
:
point
)
}
}
extension
CaptureController
{
/// Starts the timer for recording.
internal
func
startTimer
()
{
timer
?
.
invalidate
()
timer
=
Timer
(
timeInterval
:
0.5
,
target
:
self
,
selector
:
#selector(
updateTimer
)
,
userInfo
:
nil
,
repeats
:
true
)
RunLoop
.
main
.
add
(
timer
!
,
forMode
:
.
commonModes
)
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidStartRecordTimer
?(
capture
:
capture
)
}
/// Updates the timer when recording.
internal
func
updateTimer
()
{
let
duration
=
capture
.
session
.
recordedDuration
let
time
=
CMTimeGetSeconds
(
duration
)
let
hours
=
Int
(
time
/
3600
)
let
minutes
=
Int
((
time
/
60
)
.
truncatingRemainder
(
dividingBy
:
60
))
let
seconds
=
Int
(
time
.
truncatingRemainder
(
dividingBy
:
60
))
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidUpdateRecordTimer
?(
capture
:
capture
,
hours
:
hours
,
minutes
:
minutes
,
seconds
:
seconds
)
}
/// Stops the timer when recording.
internal
func
stopTimer
()
{
let
duration
=
capture
.
session
.
recordedDuration
let
time
=
CMTimeGetSeconds
(
duration
)
let
hours
=
Int
(
time
/
3600
)
let
minutes
=
Int
((
time
/
60
)
.
truncatingRemainder
(
dividingBy
:
60
))
let
seconds
=
Int
(
time
.
truncatingRemainder
(
dividingBy
:
60
))
timer
?
.
invalidate
()
timer
=
nil
(
delegate
as?
CaptureControllerDelegate
)?
.
captureDidStopRecordTimer
?(
capture
:
capture
,
hours
:
hours
,
minutes
:
minutes
,
seconds
:
seconds
)
}
}
Sources/iOS/Capture/CaptureSession.swift
View file @
124ec56c
...
...
@@ -169,7 +169,7 @@ public protocol CaptureSessionDelegate {
}
@objc(CaptureSession)
open
class
CaptureSession
:
NSObject
,
AVCaptureFileOutputRecordingDelegate
{
open
class
CaptureSession
:
NSObject
{
/// A reference to the session DispatchQueue.
private
var
sessionQueue
:
DispatchQueue
!
...
...
@@ -189,7 +189,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
private
var
movieOutputURL
:
URL
?
/// A reference to the AVCaptureSession.
internal
var
session
:
AVCaptureSession
!
internal
private(set)
var
session
:
AVCaptureSession
!
/// A boolean indicating if the session is running.
open
internal(set)
var
isRunning
=
false
...
...
@@ -376,12 +376,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
preset
=
.
presetHigh
super
.
init
()
prepareSession
()
prepareSessionQueue
()
prepareActiveVideoInput
()
prepareActiveAudioInput
()
prepareImageOutput
()
prepareMovieOutput
()
prepare
()
}
/// Starts the session.
...
...
@@ -673,16 +668,22 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
movieOutput
.
stopRecording
()
}
public
func
capture
(
_
captureOutput
:
AVCaptureFileOutput
!
,
didStartRecordingToOutputFileAt
fileURL
:
URL
!
,
fromConnections
connections
:
[
Any
]
!
)
{
isRecording
=
true
delegate
?
.
captureSessionDidStartRecordingToOutputFileAtURL
?(
session
:
self
,
captureOutput
:
captureOutput
,
fileURL
:
fileURL
as
NSURL
,
fromConnections
:
connections
)
}
public
func
capture
(
_
captureOutput
:
AVCaptureFileOutput
!
,
didFinishRecordingToOutputFileAt
outputFileURL
:
URL
!
,
fromConnections
connections
:
[
Any
]
!
,
error
:
Error
!
)
{
isRecording
=
false
delegate
?
.
captureSessionDidFinishRecordingToOutputFileAtURL
?(
session
:
self
,
captureOutput
:
captureOutput
,
outputFileURL
:
outputFileURL
as
NSURL
,
fromConnections
:
connections
,
error
:
error
)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open
func
prepare
()
{
prepareSession
()
prepareSessionQueue
()
prepareActiveVideoInput
()
prepareActiveAudioInput
()
prepareImageOutput
()
prepareMovieOutput
()
}
/// Prepares the sessionQueue.
private
func
prepareSessionQueue
()
{
...
...
@@ -781,3 +782,15 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
return
nil
}
}
extension
CaptureSession
:
AVCaptureFileOutputRecordingDelegate
{
public
func
capture
(
_
captureOutput
:
AVCaptureFileOutput
!
,
didStartRecordingToOutputFileAt
fileURL
:
URL
!
,
fromConnections
connections
:
[
Any
]
!
)
{
isRecording
=
true
delegate
?
.
captureSessionDidStartRecordingToOutputFileAtURL
?(
session
:
self
,
captureOutput
:
captureOutput
,
fileURL
:
fileURL
as
NSURL
,
fromConnections
:
connections
)
}
public
func
capture
(
_
captureOutput
:
AVCaptureFileOutput
!
,
didFinishRecordingToOutputFileAt
outputFileURL
:
URL
!
,
fromConnections
connections
:
[
Any
]
!
,
error
:
Error
!
)
{
isRecording
=
false
delegate
?
.
captureSessionDidFinishRecordingToOutputFileAtURL
?(
session
:
self
,
captureOutput
:
captureOutput
,
outputFileURL
:
outputFileURL
as
NSURL
,
fromConnections
:
connections
,
error
:
error
)
}
}
Sources/iOS/NavigationDrawerController.swift
View file @
124ec56c
...
...
@@ -307,9 +307,6 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
@IBInspectable
open
var
isHiddenStatusBarEnabled
=
true
/// Sets the statusBar to isHidden or not.
open
internal(set)
var
isStatusBarHidden
=
false
/**
A DepthPreset property that is used to set the depth of the
leftView when opened.
...
...
Sources/iOS/RootController.swift
View file @
124ec56c
...
...
@@ -40,6 +40,16 @@ open class RootController: UIViewController {
Device
.
statusBarStyle
=
value
}
}
/// Device visibility state.
open
var
isStatusBarHidden
:
Bool
{
get
{
return
Device
.
isStatusBarHidden
}
set
(
value
)
{
Device
.
isStatusBarHidden
=
value
}
}
/**
A Boolean property used to enable and disable interactivity
...
...
Sources/iOS/StatusBarController.swift
View file @
124ec56c
...
...
@@ -52,6 +52,12 @@ open class StatusBarController: RootController {
/// A reference to the statusBar.
open
private(set)
lazy
var
statusBar
=
View
()
open
override
var
isStatusBarHidden
:
Bool
{
didSet
{
statusBar
.
isHidden
=
isStatusBarHidden
}
}
/**
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment