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
12d8b112
Commit
12d8b112
authored
Dec 14, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated CaptureView example with latest changes to CaptureView
parent
4610a310
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
72 deletions
+117
-72
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+96
-53
Sources/CaptureSession.swift
+20
-18
Sources/CaptureView.swift
+1
-1
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
12d8b112
...
@@ -20,16 +20,28 @@ import UIKit
...
@@ -20,16 +20,28 @@ import UIKit
import
MaterialKit
import
MaterialKit
import
AVFoundation
import
AVFoundation
class
ViewController
:
UIViewController
,
CaptureSessionDelegate
{
class
ViewController
:
UIViewController
,
CapturePreviewViewDelegate
,
CaptureSessionDelegate
{
private
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
private
lazy
var
cameraButton
:
FlatButton
=
FlatButton
()
private
lazy
var
cameraButton
:
FlatButton
=
FlatButton
()
private
lazy
var
captureButton
:
FabButton
=
FabButton
()
private
lazy
var
captureButton
:
FabButton
=
FabButton
()
private
lazy
var
videoButton
:
FlatButton
=
FlatButton
()
private
lazy
var
videoButton
:
FlatButton
=
FlatButton
()
private
lazy
var
switchCameraButton
:
FlatButton
=
FlatButton
()
private
lazy
var
flashButton
:
FlatButton
=
FlatButton
()
private
lazy
var
closeButton
:
FlatButton
=
FlatButton
()
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareView
()
prepareCaptureView
()
prepareCaptureView
()
prepareNavigationBarView
()
prepareCaptureButton
()
prepareCameraButton
()
prepareVideoButton
()
prepareCloseButton
()
prepareSwitchCameraButton
()
prepareFlashButton
()
}
}
/**
/**
...
@@ -40,43 +52,22 @@ class ViewController: UIViewController, CaptureSessionDelegate {
...
@@ -40,43 +52,22 @@ class ViewController: UIViewController, CaptureSessionDelegate {
}
}
/**
/**
:name: prepare
Capture
View
:name: prepare
NavigationBar
View
*/
*/
private
func
prepareCaptureView
()
{
private
func
prepareNavigationBarView
()
{
let
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
navigationBarView
.
backgroundColor
=
MaterialColor
.
black
.
colorWithAlphaComponent
(
0.3
)
navigationBarView
.
backgroundColor
=
MaterialColor
.
black
.
colorWithAlphaComponent
(
0.3
)
navigationBarView
.
shadowDepth
=
.
None
navigationBarView
.
shadowDepth
=
.
None
navigationBarView
.
statusBarStyle
=
.
LightContent
navigationBarView
.
statusBarStyle
=
.
LightContent
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)
view
.
addSubview
(
navigationBarView
)
let
btn1
:
FlatButton
=
FlatButton
()
navigationBarView
.
leftButtons
=
[
closeButton
]
btn1
.
pulseColor
=
MaterialColor
.
white
navigationBarView
.
rightButtons
=
[
switchCameraButton
,
flashButton
]
btn1
.
pulseFill
=
true
}
btn1
.
setImage
(
img1
,
forState
:
.
Normal
)
btn1
.
setImage
(
img1
,
forState
:
.
Highlighted
)
/**
btn1
.
addTarget
(
self
,
action
:
"handleFlashButton:"
,
forControlEvents
:
.
TouchUpInside
)
:name: prepareCaptureButton
*/
let
img2
:
UIImage
?
=
UIImage
(
named
:
"ic_switch_camera_white"
)
private
func
prepareCaptureButton
()
{
let
btn2
:
FlatButton
=
FlatButton
()
btn2
.
pulseColor
=
MaterialColor
.
white
btn2
.
pulseFill
=
true
btn2
.
setImage
(
img2
,
forState
:
.
Normal
)
btn2
.
setImage
(
img2
,
forState
:
.
Highlighted
)
btn2
.
addTarget
(
self
,
action
:
"handleSwitchCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
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"
)
cameraButton
.
pulseColor
=
nil
cameraButton
.
setImage
(
img4
,
forState
:
.
Normal
)
cameraButton
.
setImage
(
img4
,
forState
:
.
Highlighted
)
cameraButton
.
addTarget
(
self
,
action
:
"handleCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseFill
=
true
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
...
@@ -85,37 +76,89 @@ class ViewController: UIViewController, CaptureSessionDelegate {
...
@@ -85,37 +76,89 @@ class ViewController: UIViewController, CaptureSessionDelegate {
captureButton
.
shadowDepth
=
.
None
captureButton
.
shadowDepth
=
.
None
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
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
)
}
/**
:name: prepareCameraButton
*/
private
func
prepareCameraButton
()
{
let
img4
:
UIImage
?
=
UIImage
(
named
:
"ic_photo_camera_white_36pt"
)
cameraButton
.
pulseColor
=
nil
cameraButton
.
setImage
(
img4
,
forState
:
.
Normal
)
cameraButton
.
setImage
(
img4
,
forState
:
.
Highlighted
)
cameraButton
.
addTarget
(
self
,
action
:
"handleCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
cameraButton
)
cameraButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomLeft
(
view
,
child
:
cameraButton
,
bottom
:
24
,
left
:
24
)
}
/**
:name: prepareVideoButton
*/
private
func
prepareVideoButton
()
{
let
img5
:
UIImage
?
=
UIImage
(
named
:
"ic_videocam_white_36pt"
)
let
img5
:
UIImage
?
=
UIImage
(
named
:
"ic_videocam_white_36pt"
)
videoButton
.
pulseColor
=
nil
videoButton
.
pulseColor
=
nil
videoButton
.
setImage
(
img5
,
forState
:
.
Normal
)
videoButton
.
setImage
(
img5
,
forState
:
.
Normal
)
videoButton
.
setImage
(
img5
,
forState
:
.
Highlighted
)
videoButton
.
setImage
(
img5
,
forState
:
.
Highlighted
)
videoButton
.
addTarget
(
self
,
action
:
"handleVideoButton:"
,
forControlEvents
:
.
TouchUpInside
)
videoButton
.
addTarget
(
self
,
action
:
"handleVideoButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
videoButton
)
videoButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
videoButton
,
bottom
:
24
,
right
:
24
)
}
/**
:name: prepareCloseButton
*/
private
func
prepareCloseButton
()
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_close_white"
)
closeButton
.
pulseColor
=
MaterialColor
.
white
closeButton
.
pulseFill
=
true
closeButton
.
setImage
(
img
,
forState
:
.
Normal
)
closeButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
/**
:name: prepareSwitchCameraButton
*/
private
func
prepareSwitchCameraButton
()
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_switch_camera_white"
)
switchCameraButton
.
pulseColor
=
MaterialColor
.
white
switchCameraButton
.
pulseFill
=
true
switchCameraButton
.
setImage
(
img
,
forState
:
.
Normal
)
switchCameraButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
switchCameraButton
.
addTarget
(
self
,
action
:
"handleSwitchCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
}
/**
:name: prepareFlashButton
*/
private
func
prepareFlashButton
()
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)
flashButton
.
pulseColor
=
MaterialColor
.
white
flashButton
.
pulseFill
=
true
flashButton
.
setImage
(
img
,
forState
:
.
Normal
)
flashButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
flashButton
.
addTarget
(
self
,
action
:
"handleFlashButton:"
,
forControlEvents
:
.
TouchUpInside
)
}
/**
:name: prepareCaptureView
*/
private
func
prepareCaptureView
()
{
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureButton
=
captureButton
captureView
.
captureButton
=
captureButton
captureView
.
flashButton
=
btn1
captureView
.
flashButton
=
flashButton
captureView
.
switchCamerasButton
=
btn2
captureView
.
switchCamerasButton
=
switchCameraButton
view
.
addSubview
(
captureView
)
view
.
addSubview
(
captureView
)
captureView
.
translatesAutoresizingMaskIntoConstraints
=
false
captureView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
captureView
)
MaterialLayout
.
alignToParent
(
view
,
child
:
captureView
)
view
.
addSubview
(
cameraButton
)
cameraButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomLeft
(
view
,
child
:
cameraButton
,
bottom
:
24
,
left
:
24
)
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
(
videoButton
)
videoButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
videoButton
,
bottom
:
24
,
right
:
24
)
view
.
addSubview
(
navigationBarView
)
navigationBarView
.
leftButtons
=
[
btn3
]
navigationBarView
.
rightButtons
=
[
btn1
,
btn2
]
}
}
/**
/**
...
...
Sources/CaptureSession.swift
View file @
12d8b112
...
@@ -497,25 +497,27 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -497,25 +497,27 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
:name: startRecording
:name: startRecording
*/
*/
public
func
startRecording
()
{
public
func
startRecording
()
{
if
!
isRecording
{
dispatch_async
(
videoQueue
)
{
let
connection
:
AVCaptureConnection
=
movieOutput
.
connectionWithMediaType
(
AVMediaTypeVideo
)
if
!
self
.
isRecording
{
connection
.
videoOrientation
=
currentVideoOrientation
let
connection
:
AVCaptureConnection
=
self
.
movieOutput
.
connectionWithMediaType
(
AVMediaTypeVideo
)
connection
.
preferredVideoStabilizationMode
=
.
Auto
connection
.
videoOrientation
=
self
.
currentVideoOrientation
connection
.
preferredVideoStabilizationMode
=
.
Auto
let
device
:
AVCaptureDevice
=
activeCamera
!
if
device
.
smoothAutoFocusSupported
{
let
device
:
AVCaptureDevice
=
self
.
activeCamera
!
do
{
if
device
.
smoothAutoFocusSupported
{
try
device
.
lockForConfiguration
()
do
{
device
.
smoothAutoFocusEnabled
=
true
try
device
.
lockForConfiguration
()
device
.
unlockForConfiguration
()
device
.
smoothAutoFocusEnabled
=
true
}
catch
let
e
as
NSError
{
device
.
unlockForConfiguration
()
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
}
catch
let
e
as
NSError
{
self
.
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
}
}
self
.
movieOutputURL
=
self
.
uniqueURL
()
if
let
v
:
NSURL
=
self
.
movieOutputURL
{
self
.
movieOutput
.
startRecordingToOutputFileURL
(
v
,
recordingDelegate
:
self
)
}
}
}
movieOutputURL
=
uniqueURL
()
if
let
v
:
NSURL
=
movieOutputURL
{
movieOutput
.
startRecordingToOutputFileURL
(
v
,
recordingDelegate
:
self
)
}
}
}
}
}
}
...
...
Sources/CaptureView.swift
View file @
12d8b112
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
import
UIKit
import
UIKit
public
class
CaptureView
:
MaterialView
,
Capture
SessionDelegate
,
Capture
PreviewViewDelegate
{
public
class
CaptureView
:
MaterialView
,
CapturePreviewViewDelegate
{
/**
/**
:name: previewView
:name: previewView
*/
*/
...
...
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