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
0486e49e
Commit
0486e49e
authored
Dec 13, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CaptureView Example working with still image capture
parent
b040107c
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
157 additions
and
38 deletions
+157
-38
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/Contents.json
+24
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white@2x.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white@3x.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/Contents.json
+24
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt@2x.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt@3x.png
+0
-0
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+37
-2
Sources/CaptureSession.swift
+40
-0
Sources/CaptureView.swift
+32
-36
No files found.
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/Contents.json
0 → 100644
View file @
0486e49e
{
"images"
:
[
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white.png"
,
"scale"
:
"1x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white@2x.png"
,
"scale"
:
"2x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white@3x.png"
,
"scale"
:
"3x"
}
],
"info"
:
{
"version"
:
1
,
"author"
:
"xcode"
}
}
\ No newline at end of file
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white.png
0 → 100644
View file @
0486e49e
240 Bytes
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white@2x.png
0 → 100644
View file @
0486e49e
446 Bytes
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white.imageset/ic_photo_camera_white@3x.png
0 → 100644
View file @
0486e49e
666 Bytes
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/Contents.json
0 → 100644
View file @
0486e49e
{
"images"
:
[
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white_36pt.png"
,
"scale"
:
"1x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white_36pt@2x.png"
,
"scale"
:
"2x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_photo_camera_white_36pt@3x.png"
,
"scale"
:
"3x"
}
],
"info"
:
{
"version"
:
1
,
"author"
:
"xcode"
}
}
\ No newline at end of file
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt.png
0 → 100644
View file @
0486e49e
364 Bytes
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt@2x.png
0 → 100644
View file @
0486e49e
666 Bytes
Examples/Programmatic/CaptureView/CaptureView/Assets.xcassets/ic_photo_camera_white_36pt.imageset/ic_photo_camera_white_36pt@3x.png
0 → 100644
View file @
0486e49e
985 Bytes
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
0486e49e
...
...
@@ -19,7 +19,7 @@
import
UIKit
import
MaterialKit
class
ViewController
:
UIViewController
{
class
ViewController
:
UIViewController
,
CaptureSessionDelegate
{
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
override
func
viewDidLoad
()
{
...
...
@@ -39,6 +39,11 @@ class ViewController: UIViewController {
:name: prepareCaptureView
*/
private
func
prepareCaptureView
()
{
let
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
navigationBarView
.
backgroundColor
=
MaterialColor
.
black
.
colorWithAlphaComponent
(
0.3
)
navigationBarView
.
shadowDepth
=
.
None
navigationBarView
.
statusBarStyle
=
.
LightContent
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)
let
btn1
:
FlatButton
=
FlatButton
()
btn1
.
pulseColor
=
nil
...
...
@@ -51,14 +56,32 @@ class ViewController: UIViewController {
btn2
.
pulseColor
=
nil
btn2
.
setImage
(
img2
,
forState
:
.
Normal
)
btn2
.
setImage
(
img2
,
forState
:
.
Highlighted
)
let
img3
:
UIImage
?
=
UIImage
(
named
:
"ic_photo_camera_white_36pt"
)
let
captureButton
:
FabButton
=
FabButton
()
captureButton
.
backgroundColor
=
MaterialColor
.
grey
.
darken2
captureButton
.
borderWidth
=
.
Border4
captureButton
.
borderColor
=
MaterialColor
.
white
captureButton
.
shadowDepth
=
.
None
captureButton
.
setImage
(
img3
,
forState
:
.
Normal
)
captureButton
.
setImage
(
img3
,
forState
:
.
Highlighted
)
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureButton
=
captureButton
captureView
.
flashAutoButton
=
btn1
captureView
.
switchCamerasButton
=
btn2
captureView
.
navigationBarView
.
rightButtons
=
[
btn1
,
btn2
]
view
.
addSubview
(
captureView
)
captureView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
captureView
)
view
.
addSubview
(
captureButton
)
captureButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
captureButton
,
bottom
:
24
,
right
:
(
view
.
bounds
.
width
-
72
)
/
2
)
MaterialLayout
.
size
(
view
,
child
:
captureButton
,
width
:
72
,
height
:
72
)
view
.
addSubview
(
navigationBarView
)
navigationBarView
.
rightButtons
=
[
btn1
,
btn2
]
}
internal
func
handleFlash
(
sender
:
AnyObject
)
{
...
...
@@ -77,5 +100,17 @@ class ViewController: UIViewController {
captureView
.
flashAutoButton
?
.
setImage
(
img
,
forState
:
.
Normal
)
captureView
.
flashAutoButton
?
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
/**
:name: captureSessionFailedWithError
*/
func
captureSessionFailedWithError
(
capture
:
CaptureSession
,
error
:
NSError
)
{
print
(
error
)
}
func
captureStillImageAsynchronously
(
capture
:
CaptureSession
,
image
:
UIImage
?,
error
:
NSError
?)
{
print
(
image
)
print
(
error
)
}
}
Sources/CaptureSession.swift
View file @
0486e49e
...
...
@@ -41,6 +41,11 @@ public protocol CaptureSessionDelegate {
:name: captureSessionFailedWithError
*/
optional
func
captureSessionFailedWithError
(
capture
:
CaptureSession
,
error
:
NSError
)
/**
:name: captureStillImageAsynchronously
*/
optional
func
captureStillImageAsynchronously
(
capture
:
CaptureSession
,
image
:
UIImage
?,
error
:
NSError
?)
}
@objc(CaptureSession)
...
...
@@ -244,6 +249,24 @@ public class CaptureSession : NSObject {
}
/**
:name: sessionPreset
*/
public
var
currentVideoOrientation
:
AVCaptureVideoOrientation
{
var
orientation
:
AVCaptureVideoOrientation
switch
UIDevice
.
currentDevice
()
.
orientation
{
case
.
Portrait
:
orientation
=
.
Portrait
case
.
LandscapeRight
:
orientation
=
.
LandscapeLeft
case
.
PortraitUpsideDown
:
orientation
=
.
PortraitUpsideDown
default
:
orientation
=
.
LandscapeRight
}
return
orientation
}
/**
:name: delegate
*/
public
weak
var
delegate
:
CaptureSessionDelegate
?
...
...
@@ -420,6 +443,23 @@ public class CaptureSession : NSObject {
}
/**
:name: captureStillImage
*/
public
func
captureStillImage
()
{
let
connection
:
AVCaptureConnection
=
imageOutput
.
connectionWithMediaType
(
AVMediaTypeVideo
)
connection
.
videoOrientation
=
currentVideoOrientation
imageOutput
.
captureStillImageAsynchronouslyFromConnection
(
connection
)
{
(
sampleBuffer
:
CMSampleBuffer
!
,
error
:
NSError
!
)
->
Void
in
if
nil
==
error
{
let
data
:
NSData
=
AVCaptureStillImageOutput
.
jpegStillImageNSDataRepresentation
(
sampleBuffer
)
self
.
delegate
?
.
captureStillImageAsynchronously
?(
self
,
image
:
UIImage
(
data
:
data
),
error
:
nil
)
}
else
{
self
.
delegate
?
.
captureStillImageAsynchronously
?(
self
,
image
:
nil
,
error
:
error
)
}
}
}
/**
:name: prepareSession
*/
private
func
prepareSession
()
{
...
...
Sources/CaptureView.swift
View file @
0486e49e
...
...
@@ -35,16 +35,26 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
public
private(set)
lazy
var
exposureLayer
:
MaterialLayer
=
MaterialLayer
()
/**
:name:
navigationBarView
:name:
captureButton
*/
public
private(set)
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
public
var
captureButton
:
UIButton
?
{
didSet
{
if
let
v
:
UIButton
=
captureButton
{
v
.
removeTarget
(
self
,
action
:
"handleCapture:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleCapture:"
,
forControlEvents
:
.
TouchUpInside
)
}
else
{
captureButton
?
.
removeFromSuperview
()
captureButton
=
nil
}
}
}
/**
:name: flashAutoButton
*/
public
var
flashAutoButton
:
Material
Button
?
{
public
var
flashAutoButton
:
UI
Button
?
{
didSet
{
if
let
v
:
Material
Button
=
flashAutoButton
{
if
let
v
:
UI
Button
=
flashAutoButton
{
v
.
removeTarget
(
self
,
action
:
"handleFlashAuto:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleFlashAuto:"
,
forControlEvents
:
.
TouchUpInside
)
}
else
{
...
...
@@ -57,9 +67,9 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
/**
:name: switchCamerasButton
*/
public
var
switchCamerasButton
:
Material
Button
?
{
public
var
switchCamerasButton
:
UI
Button
?
{
didSet
{
if
let
v
:
Material
Button
=
switchCamerasButton
{
if
let
v
:
UI
Button
=
switchCamerasButton
{
v
.
removeTarget
(
self
,
action
:
"handleSwitchCamera:"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleSwitchCamera:"
,
forControlEvents
:
.
TouchUpInside
)
}
else
{
...
...
@@ -97,6 +107,13 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
/**
:name: captureSession
*/
public
var
captureSession
:
CaptureSession
{
return
previewView
.
captureSession
}
/**
:name: init
*/
public
convenience
init
()
{
...
...
@@ -125,23 +142,6 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
addSubview
(
previewView
)
MaterialLayout
.
alignToParent
(
self
,
child
:
previewView
)
addSubview
(
navigationBarView
)
// var verticalFormat: String = "V:|"
// var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// if 0 < views.count {
// addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
// }
}
/**
:name: captureSessionFailedWithError
*/
public
func
captureSessionFailedWithError
(
capture
:
CaptureSession
,
error
:
NSError
)
{
print
(
error
)
}
/**
...
...
@@ -194,23 +194,29 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
public
override
func
prepareView
()
{
super
.
prepareView
()
preparePreviewView
()
prepareNavigationBarView
()
prepareFocusLayer
()
prepareExposureLayer
()
reloadView
()
}
/**
:name: handleCapture
*/
internal
func
handleCapture
(
button
:
UIButton
)
{
previewView
.
captureSession
.
captureStillImage
()
}
/**
:name: handleSwitchCamera
*/
internal
func
handleSwitchCamera
(
button
:
Material
Button
)
{
internal
func
handleSwitchCamera
(
button
:
UI
Button
)
{
previewView
.
captureSession
.
switchCameras
()
}
/**
:name: handleFlashAuto
*/
internal
func
handleFlashAuto
(
button
:
Material
Button
)
{
internal
func
handleFlashAuto
(
button
:
UI
Button
)
{
switch
previewView
.
captureSession
.
flashMode
{
case
.
Off
:
previewView
.
captureSession
.
flashMode
=
.
On
...
...
@@ -225,20 +231,10 @@ public class CaptureView : MaterialView, CaptureSessionDelegate, CapturePreviewV
}
/**
:name: prepareNavigationBarView
*/
private
func
prepareNavigationBarView
()
{
navigationBarView
.
backgroundColor
=
MaterialColor
.
black
.
colorWithAlphaComponent
(
0.3
)
navigationBarView
.
shadowDepth
=
.
None
navigationBarView
.
statusBarStyle
=
.
LightContent
}
/**
:name: preparePreviewView
*/
private
func
preparePreviewView
()
{
previewView
.
translatesAutoresizingMaskIntoConstraints
=
false
previewView
.
captureSession
.
delegate
=
self
previewView
.
delegate
=
self
previewView
.
captureSession
.
startSession
()
}
...
...
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