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
30b1d92e
Commit
30b1d92e
authored
Dec 14, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated CaptureView and example project.
parent
0486e49e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
78 deletions
+55
-78
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+21
-11
Sources/CaptureSession.swift
+5
-5
Sources/CaptureView.swift
+26
-56
Sources/MaterialTheme.swift
+3
-6
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
30b1d92e
...
@@ -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
=
.
Border
4
captureButton
.
borderWidth
=
.
Border
2
captureButton
.
borderColor
=
MaterialColor
.
white
captureButton
.
borderColor
=
MaterialColor
.
grey
.
darken1
captureButton
.
shadowDepth
=
.
None
captureButton
.
shadowDepth
=
.
None
captureButton
.
setImage
(
img
3
,
forState
:
.
Normal
)
captureButton
.
setImage
(
img
4
,
forState
:
.
Normal
)
captureButton
.
setImage
(
img
3
,
forState
:
.
Highlighted
)
captureButton
.
setImage
(
img
4
,
forState
:
.
Highlighted
)
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureButton
=
captureButton
captureView
.
captureButton
=
captureButton
captureView
.
flash
Auto
Button
=
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
.
flash
Auto
Button
?
.
setImage
(
img
,
forState
:
.
Normal
)
captureView
.
flashButton
?
.
setImage
(
img
,
forState
:
.
Normal
)
captureView
.
flash
Auto
Button
?
.
setImage
(
img
,
forState
:
.
Highlighted
)
captureView
.
flashButton
?
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
}
/**
/**
...
...
Sources/CaptureSession.swift
View file @
30b1d92e
...
@@ -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
active
VideoInput
!.
device
.
isFocusModeSupported
(
focusMode
)
return
active
Camera
!
.
isFocusModeSupported
(
focusMode
)
}
}
/**
/**
:name: isExposureModeSupported
:name: isExposureModeSupported
*/
*/
public
func
isExposureModeSupported
(
exposureMode
:
AVCaptureExposureMode
)
->
Bool
{
public
func
isExposureModeSupported
(
exposureMode
:
AVCaptureExposureMode
)
->
Bool
{
return
active
VideoInput
!.
device
.
isExposureModeSupported
(
exposureMode
)
return
active
Camera
!
.
isExposureModeSupported
(
exposureMode
)
}
}
/**
/**
:name: isFlashModeSupported
:name: isFlashModeSupported
*/
*/
public
func
isFlashModeSupported
(
flashMode
:
AVCaptureFlashMode
)
->
Bool
{
public
func
isFlashModeSupported
(
flashMode
:
AVCaptureFlashMode
)
->
Bool
{
return
active
VideoInput
!.
device
.
isFlashModeSupported
(
flashMode
)
return
active
Camera
!
.
isFlashModeSupported
(
flashMode
)
}
}
/**
/**
:name: isTorchModeSupported
:name: isTorchModeSupported
*/
*/
public
func
isTorchModeSupported
(
torchMode
:
AVCaptureTorchMode
)
->
Bool
{
public
func
isTorchModeSupported
(
torchMode
:
AVCaptureTorchMode
)
->
Bool
{
return
active
VideoInput
!.
device
.
isTorchModeSupported
(
torchMode
)
return
active
Camera
!
.
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
)
}
}
}
}
...
...
Sources/CaptureView.swift
View file @
30b1d92e
...
@@ -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
:
"handleCapture
Button
:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleCapture:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleCapture
Button
:"
,
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: flash
Auto
Button
:name: flashButton
*/
*/
public
var
flash
Auto
Button
:
UIButton
?
{
public
var
flashButton
:
UIButton
?
{
didSet
{
didSet
{
if
let
v
:
UIButton
=
flash
Auto
Button
{
if
let
v
:
UIButton
=
flashButton
{
v
.
removeTarget
(
self
,
action
:
"handleFlash
Auto
:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
removeTarget
(
self
,
action
:
"handleFlash
Button
:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleFlash
Auto
:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleFlash
Button
:"
,
forControlEvents
:
.
TouchUpInside
)
}
else
{
}
else
{
flash
Auto
Button
?
.
removeFromSuperview
()
flashButton
?
.
removeFromSuperview
()
flash
Auto
Button
=
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
:
"handleSwitchCamera
Button
:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleSwitchCamera:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleSwitchCamera
Button
:"
,
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: handleCapture
Button
*/
*/
internal
func
handleCapture
(
button
:
UIButton
)
{
internal
func
handleCapture
Button
(
button
:
UIButton
)
{
previewView
.
captureSession
.
captureStillImage
()
captureSession
.
captureStillImage
()
}
}
/**
/**
:name: handleSwitchCamera
:name: handleSwitchCamera
Button
*/
*/
internal
func
handleSwitchCamera
(
button
:
UIButton
)
{
internal
func
handleSwitchCamera
Button
(
button
:
UIButton
)
{
previewView
.
captureSession
.
switchCameras
()
captureSession
.
switchCameras
()
}
}
/**
/**
:name: handleFlash
Auto
:name: handleFlash
Button
*/
*/
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
}
}
}
}
...
...
Sources/MaterialTheme.swift
View file @
30b1d92e
...
@@ -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
basicC
aptureView
{}
public
struct
c
aptureView
{}
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
}
}
//
basicC
aptureView
//
c
aptureView
public
extension
MaterialTheme
.
basicC
aptureView
{
public
extension
MaterialTheme
.
c
aptureView
{
// 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
...
...
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