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
16f980b2
Commit
16f980b2
authored
Dec 12, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Reset Exposure and Focus with animation
parent
cc1668fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
4 deletions
+83
-4
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+4
-1
Sources/CapturePreviewView.swift
+47
-3
Sources/CaptureSession.swift
+24
-0
Sources/CaptureView.swift
+8
-0
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
16f980b2
...
@@ -41,7 +41,10 @@ class ViewController: UIViewController {
...
@@ -41,7 +41,10 @@ class ViewController: UIViewController {
:description: General usage example.
:description: General usage example.
*/
*/
private
func
prepareGeneralCaptureViewExample
()
{
private
func
prepareGeneralCaptureViewExample
()
{
let
v
:
CaptureView
=
CaptureView
(
frame
:
view
.
bounds
)
v
.
switchCamerasButton
=
FabButton
()
view
.
addSubview
(
v
)
}
}
}
}
Sources/CapturePreviewView.swift
View file @
16f980b2
...
@@ -30,6 +30,11 @@ public protocol CapturePreviewViewDelegate : MaterialDelegate {
...
@@ -30,6 +30,11 @@ public protocol CapturePreviewViewDelegate : MaterialDelegate {
:name: capturePreviewViewDidTapToExposeAtPoint
:name: capturePreviewViewDidTapToExposeAtPoint
*/
*/
optional
func
capturePreviewViewDidTapToExposeAtPoint
(
capturePreviewView
:
CapturePreviewView
,
point
:
CGPoint
)
optional
func
capturePreviewViewDidTapToExposeAtPoint
(
capturePreviewView
:
CapturePreviewView
,
point
:
CGPoint
)
/**
:name: capturePreviewViewDidTapToResetAtPoint
*/
optional
func
capturePreviewViewDidTapToResetAtPoint
(
capturePreviewView
:
CapturePreviewView
,
point
:
CGPoint
)
}
}
public
class
CapturePreviewView
:
MaterialView
,
UIGestureRecognizerDelegate
{
public
class
CapturePreviewView
:
MaterialView
,
UIGestureRecognizerDelegate
{
...
@@ -44,6 +49,11 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -44,6 +49,11 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
private
var
tapToExposeGesture
:
UITapGestureRecognizer
?
private
var
tapToExposeGesture
:
UITapGestureRecognizer
?
/**
/**
:name: tapToResetGesture
*/
private
var
tapToResetGesture
:
UITapGestureRecognizer
?
/**
:name: previewLayer
:name: previewLayer
*/
*/
public
private(set)
lazy
var
previewLayer
:
AVCaptureVideoPreviewLayer
=
AVCaptureVideoPreviewLayer
()
public
private(set)
lazy
var
previewLayer
:
AVCaptureVideoPreviewLayer
=
AVCaptureVideoPreviewLayer
()
...
@@ -59,7 +69,8 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -59,7 +69,8 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
public
var
tapToFocusEnabled
:
Bool
{
public
var
tapToFocusEnabled
:
Bool
{
didSet
{
didSet
{
if
tapToFocusEnabled
{
if
tapToFocusEnabled
{
prepareTapGesture
(
&
tapToFocusGesture
,
numberOfTapsRequired
:
1
,
selector
:
"handleTapToFocusGesture:"
)
tapToResetEnabled
=
true
prepareTapGesture
(
&
tapToFocusGesture
,
numberOfTapsRequired
:
1
,
numberOfTouchesRequired
:
1
,
selector
:
"handleTapToFocusGesture:"
)
if
let
v
:
UITapGestureRecognizer
=
tapToExposeGesture
{
if
let
v
:
UITapGestureRecognizer
=
tapToExposeGesture
{
tapToFocusGesture
!.
requireGestureRecognizerToFail
(
v
)
tapToFocusGesture
!.
requireGestureRecognizerToFail
(
v
)
}
}
...
@@ -75,7 +86,8 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -75,7 +86,8 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
public
var
tapToExposeEnabled
:
Bool
{
public
var
tapToExposeEnabled
:
Bool
{
didSet
{
didSet
{
if
tapToExposeEnabled
{
if
tapToExposeEnabled
{
prepareTapGesture
(
&
tapToExposeGesture
,
numberOfTapsRequired
:
2
,
selector
:
"handleTapToExposeGesture:"
)
tapToResetEnabled
=
true
prepareTapGesture
(
&
tapToExposeGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
1
,
selector
:
"handleTapToExposeGesture:"
)
if
let
v
:
UITapGestureRecognizer
=
tapToFocusGesture
{
if
let
v
:
UITapGestureRecognizer
=
tapToFocusGesture
{
v
.
requireGestureRecognizerToFail
(
tapToExposeGesture
!
)
v
.
requireGestureRecognizerToFail
(
tapToExposeGesture
!
)
}
}
...
@@ -86,11 +98,31 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -86,11 +98,31 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
}
}
/**
/**
:name: tapToResetEnabled
*/
public
var
tapToResetEnabled
:
Bool
{
didSet
{
if
tapToResetEnabled
{
prepareTapGesture
(
&
tapToResetGesture
,
numberOfTapsRequired
:
2
,
numberOfTouchesRequired
:
2
,
selector
:
"handleTapToResetGesture:"
)
if
let
v
:
UITapGestureRecognizer
=
tapToFocusGesture
{
v
.
requireGestureRecognizerToFail
(
tapToResetGesture
!
)
}
if
let
v
:
UITapGestureRecognizer
=
tapToExposeGesture
{
v
.
requireGestureRecognizerToFail
(
tapToResetGesture
!
)
}
}
else
{
removeTapGesture
(
&
tapToResetGesture
)
}
}
}
/**
:name: init
:name: init
*/
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
tapToFocusEnabled
=
true
tapToFocusEnabled
=
true
tapToExposeEnabled
=
true
tapToExposeEnabled
=
true
tapToResetEnabled
=
true
super
.
init
(
coder
:
aDecoder
)
super
.
init
(
coder
:
aDecoder
)
}
}
...
@@ -100,6 +132,7 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -100,6 +132,7 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
public
override
init
(
frame
:
CGRect
)
{
public
override
init
(
frame
:
CGRect
)
{
tapToFocusEnabled
=
true
tapToFocusEnabled
=
true
tapToExposeEnabled
=
true
tapToExposeEnabled
=
true
tapToResetEnabled
=
true
super
.
init
(
frame
:
frame
)
super
.
init
(
frame
:
frame
)
}
}
...
@@ -167,6 +200,15 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -167,6 +200,15 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
}
}
/**
/**
:name: handleTapToResetGesture
*/
internal
func
handleTapToResetGesture
(
recognizer
:
UITapGestureRecognizer
)
{
if
tapToResetEnabled
{
(
delegate
as?
CapturePreviewViewDelegate
)?
.
capturePreviewViewDidTapToResetAtPoint
?(
self
,
point
:
pointForCaptureDevicePointOfInterest
(
CGPointMake
(
0.5
,
0.5
)))
}
}
/**
:name: preparePreviewLayer
:name: preparePreviewLayer
*/
*/
private
func
preparePreviewLayer
()
{
private
func
preparePreviewLayer
()
{
...
@@ -187,10 +229,12 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -187,10 +229,12 @@ public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
/**
/**
:name: prepareTapGesture
:name: prepareTapGesture
*/
*/
private
func
prepareTapGesture
(
inout
gesture
:
UITapGestureRecognizer
?,
numberOfTapsRequired
:
Int
,
selector
:
Selector
)
{
private
func
prepareTapGesture
(
inout
gesture
:
UITapGestureRecognizer
?,
numberOfTapsRequired
:
Int
,
numberOfTouchesRequired
:
Int
,
selector
:
Selector
)
{
removeTapGesture
(
&
gesture
)
gesture
=
UITapGestureRecognizer
(
target
:
self
,
action
:
selector
)
gesture
=
UITapGestureRecognizer
(
target
:
self
,
action
:
selector
)
gesture
!.
delegate
=
self
gesture
!.
delegate
=
self
gesture
!.
numberOfTapsRequired
=
numberOfTapsRequired
gesture
!.
numberOfTapsRequired
=
numberOfTapsRequired
gesture
!.
numberOfTouchesRequired
=
numberOfTouchesRequired
addGestureRecognizer
(
gesture
!
)
addGestureRecognizer
(
gesture
!
)
}
}
...
...
Sources/CaptureSession.swift
View file @
16f980b2
...
@@ -314,6 +314,30 @@ public class CaptureSession : NSObject {
...
@@ -314,6 +314,30 @@ public class CaptureSession : NSObject {
}
}
/**
/**
:name: resetFocusAndExposureModes
*/
public
func
resetFocusAndExposureModes
()
{
let
device
:
AVCaptureDevice
=
activeCamera
!
let
canResetFocus
:
Bool
=
device
.
focusPointOfInterestSupported
&&
device
.
isFocusModeSupported
(
.
ContinuousAutoFocus
)
let
canResetExposure
:
Bool
=
device
.
exposurePointOfInterestSupported
&&
device
.
isExposureModeSupported
(
.
ContinuousAutoExposure
)
let
centerPoint
:
CGPoint
=
CGPointMake
(
0.5
,
0.5
)
do
{
try
device
.
lockForConfiguration
()
if
canResetFocus
{
device
.
focusMode
=
.
ContinuousAutoFocus
device
.
focusPointOfInterest
=
centerPoint
}
if
canResetExposure
{
device
.
exposureMode
=
.
ContinuousAutoExposure
device
.
exposurePointOfInterest
=
centerPoint
}
device
.
unlockForConfiguration
()
}
catch
let
e
as
NSError
{
self
.
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
}
}
/**
:name: prepareSession
:name: prepareSession
*/
*/
private
func
prepareSession
()
{
private
func
prepareSession
()
{
...
...
Sources/CaptureView.swift
View file @
16f980b2
...
@@ -162,6 +162,14 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
...
@@ -162,6 +162,14 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
}
}
}
}
}
/**
:name: capturePreviewViewDidTapToResetAtPoint
*/
public
func
capturePreviewViewDidTapToResetAtPoint
(
capturePreviewView
:
CapturePreviewView
,
point
:
CGPoint
)
{
capturePreviewViewDidTapToFocusAtPoint
(
capturePreviewView
,
point
:
point
)
capturePreviewViewDidTapToExposeAtPoint
(
capturePreviewView
,
point
:
point
)
}
/**
/**
:name: prepareView
:name: prepareView
...
...
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