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
2685c8f6
Commit
2685c8f6
authored
Dec 16, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated CaptureView orientation detection and layout
parent
c5437c46
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
39 deletions
+127
-39
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+22
-28
Sources/CaptureView.swift
+95
-10
Sources/MaterialTheme.swift
+10
-1
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
2685c8f6
...
...
@@ -20,11 +20,6 @@ import UIKit
import
MaterialKit
import
AVFoundation
enum
CaptureMode
{
case
Photo
case
Video
}
class
ViewController
:
UIViewController
,
CaptureViewDelegate
,
CaptureSessionDelegate
{
lazy
var
captureView
:
CaptureView
=
CaptureView
()
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
(
frame
:
CGRectNull
)
...
...
@@ -51,21 +46,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
captureButton
.
frame
=
CGRectMake
((
view
.
bounds
.
width
-
72
)
/
2
,
view
.
bounds
.
height
-
100
,
72
,
72
)
}
private
func
prepareCaptureView
()
{
view
.
addSubview
(
captureView
)
captureView
.
translatesAutoresizingMaskIntoConstraints
=
false
captureView
.
delegate
=
self
MaterialLayout
.
alignToParent
(
view
,
child
:
captureView
)
}
/**
:name: prepareView
*/
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
}
/**
...
...
@@ -260,6 +241,23 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
}
/**
:name: prepareView
*/
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
black
}
/**
:name: prepareCaptureView
*/
private
func
prepareCaptureView
()
{
view
.
addSubview
(
captureView
)
captureView
.
translatesAutoresizingMaskIntoConstraints
=
false
captureView
.
delegate
=
self
MaterialLayout
.
alignToParent
(
view
,
child
:
captureView
)
}
/**
:name: prepareNavigationBarView
*/
private
func
prepareNavigationBarView
()
{
...
...
@@ -298,6 +296,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
:name: prepareCaptureButton
*/
private
func
prepareCaptureButton
()
{
captureButton
.
width
=
72
captureButton
.
height
=
72
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
...
...
@@ -306,6 +306,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
captureButton
.
shadowDepth
=
.
None
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
captureButton
)
captureView
.
captureButton
=
captureButton
}
/**
...
...
@@ -318,11 +320,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
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
)
captureView
.
captureButton
=
cameraButton
captureView
.
cameraButton
=
cameraButton
}
/**
...
...
@@ -335,10 +333,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
videoButton
.
setImage
(
img5
,
forState
:
.
Highlighted
)
videoButton
.
addTarget
(
self
,
action
:
"handleVideoButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
videoButton
)
videoButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
videoButton
,
bottom
:
24
,
right
:
24
)
captureView
.
videoButton
=
videoButton
}
...
...
Sources/CaptureView.swift
View file @
2685c8f6
...
...
@@ -19,6 +19,11 @@
import
UIKit
import
AVFoundation
public
enum
CaptureMode
{
case
Photo
case
Video
}
@objc(CaptureViewDelegate)
public
protocol
CaptureViewDelegate
:
MaterialDelegate
{
/**
...
...
@@ -93,6 +98,24 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
}
/**
:name: contentInsets
*/
public
var
contentInsets
:
MaterialEdgeInsets
=
.
None
{
didSet
{
contentInsetsRef
=
MaterialEdgeInsetsToValue
(
contentInsets
)
}
}
/**
:name: contentInsetsRef
*/
public
var
contentInsetsRef
:
UIEdgeInsets
=
MaterialTheme
.
captureView
.
contentInsetsRef
{
didSet
{
reloadView
()
}
}
/**
:name: previewView
*/
public
private(set)
lazy
var
previewView
:
CapturePreviewView
=
CapturePreviewView
()
...
...
@@ -146,7 +169,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: cameraButton
*/
public
var
cameraButton
:
MaterialButton
?
public
var
cameraButton
:
MaterialButton
?
{
didSet
{
cameraButton
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
:name: captureButton
...
...
@@ -156,7 +184,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: videoButton
*/
public
var
videoButton
:
MaterialButton
?
public
var
videoButton
:
MaterialButton
?
{
didSet
{
videoButton
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
:name: switchCameraButton
...
...
@@ -169,11 +202,67 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
public
var
flashButton
:
MaterialButton
?
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
/**
:name: layoutSubviews
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
let
v
:
MaterialButton
=
captureButton
{
v
.
y
=
bounds
.
height
-
contentInsetsRef
.
bottom
-
v
.
height
v
.
x
=
(
bounds
.
width
-
v
.
width
)
/
2
}
(
previewView
.
layer
as!
AVCaptureVideoPreviewLayer
)
.
connection
.
videoOrientation
=
captureSession
.
currentVideoOrientation
}
/**
:name: prepareView
*/
public
override
func
prepareView
()
{
super
.
prepareView
()
prepareCapturePreviewView
()
userInteractionEnabled
=
MaterialTheme
.
captureView
.
userInteractionEnabled
backgroundColor
=
MaterialTheme
.
captureView
.
backgroundColor
contentsRect
=
MaterialTheme
.
captureView
.
contentsRect
contentsCenter
=
MaterialTheme
.
captureView
.
contentsCenter
contentsScale
=
MaterialTheme
.
captureView
.
contentsScale
contentsGravity
=
MaterialTheme
.
captureView
.
contentsGravity
shadowDepth
=
MaterialTheme
.
captureView
.
shadowDepth
shadowColor
=
MaterialTheme
.
captureView
.
shadowColor
zPosition
=
MaterialTheme
.
captureView
.
zPosition
borderWidth
=
MaterialTheme
.
captureView
.
borderWidth
borderColor
=
MaterialTheme
.
captureView
.
bordercolor
preparePreviewView
()
}
/**
:name: reloadView
*/
public
func
reloadView
()
{
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
addSubview
(
previewView
)
MaterialLayout
.
alignToParent
(
self
,
child
:
previewView
)
if
let
v
:
MaterialButton
=
cameraButton
{
addSubview
(
v
)
MaterialLayout
.
alignFromBottomLeft
(
self
,
child
:
v
,
bottom
:
contentInsetsRef
.
bottom
,
left
:
contentInsetsRef
.
left
)
}
if
let
v
:
MaterialButton
=
videoButton
{
addSubview
(
v
)
MaterialLayout
.
alignFromBottomRight
(
self
,
child
:
v
,
bottom
:
contentInsetsRef
.
bottom
,
right
:
contentInsetsRef
.
right
)
}
}
/**
...
...
@@ -284,14 +373,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
}
/**
:name: prepare
Capture
PreviewView
:name: preparePreviewView
*/
private
func
prepareCapturePreviewView
()
{
private
func
preparePreviewView
()
{
previewView
.
translatesAutoresizingMaskIntoConstraints
=
false
(
previewView
.
layer
as!
AVCaptureVideoPreviewLayer
)
.
session
=
captureSession
.
session
captureSession
.
startSession
()
addSubview
(
previewView
)
previewView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
self
,
child
:
previewView
)
}
/**
...
...
@@ -299,7 +386,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
*/
private
func
prepareFocusView
()
{
if
let
v
:
MaterialView
=
focusView
{
addSubview
(
v
)
v
.
hidden
=
true
}
}
...
...
@@ -309,7 +395,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
*/
private
func
prepareExposureView
()
{
if
let
v
:
MaterialView
=
exposureView
{
addSubview
(
v
)
v
.
hidden
=
true
}
}
...
...
Sources/MaterialTheme.swift
View file @
2685c8f6
...
...
@@ -208,9 +208,12 @@ public extension MaterialTheme.navigationBarView {
// captureView
public
extension
MaterialTheme
.
captureView
{
// shadow
public
static
var
shadowDepth
:
MaterialDepth
=
.
Depth2
public
static
var
shadowDepth
:
MaterialDepth
=
.
None
public
static
var
shadowColor
:
UIColor
=
MaterialColor
.
black
// shape
public
static
var
contentInsetsRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square4
)
// border
public
static
var
borderWidth
:
MaterialBorder
=
.
None
public
static
var
bordercolor
:
UIColor
=
MaterialColor
.
black
...
...
@@ -221,6 +224,12 @@ public extension MaterialTheme.captureView {
// interaction
public
static
var
userInteractionEnabled
:
Bool
=
true
// image
public
static
var
contentsRect
:
CGRect
=
CGRectMake
(
0
,
0
,
1
,
1
)
public
static
var
contentsCenter
:
CGRect
=
CGRectMake
(
0
,
0
,
1
,
1
)
public
static
var
contentsScale
:
CGFloat
=
UIScreen
.
mainScreen
()
.
scale
public
static
var
contentsGravity
:
MaterialGravity
=
.
ResizeAspectFill
// position
public
static
var
zPosition
:
CGFloat
=
0
}
...
...
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