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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
128 additions
and
40 deletions
+128
-40
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+23
-29
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
...
@@ -20,11 +20,6 @@ import UIKit
import
MaterialKit
import
MaterialKit
import
AVFoundation
import
AVFoundation
enum
CaptureMode
{
case
Photo
case
Video
}
class
ViewController
:
UIViewController
,
CaptureViewDelegate
,
CaptureSessionDelegate
{
class
ViewController
:
UIViewController
,
CaptureViewDelegate
,
CaptureSessionDelegate
{
lazy
var
captureView
:
CaptureView
=
CaptureView
()
lazy
var
captureView
:
CaptureView
=
CaptureView
()
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
(
frame
:
CGRectNull
)
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
(
frame
:
CGRectNull
)
...
@@ -51,21 +46,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -51,21 +46,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
override
func
viewWillLayoutSubviews
()
{
override
func
viewWillLayoutSubviews
()
{
super
.
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
...
@@ -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
:name: prepareNavigationBarView
*/
*/
private
func
prepareNavigationBarView
()
{
private
func
prepareNavigationBarView
()
{
...
@@ -298,6 +296,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -298,6 +296,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
:name: prepareCaptureButton
:name: prepareCaptureButton
*/
*/
private
func
prepareCaptureButton
()
{
private
func
prepareCaptureButton
()
{
captureButton
.
width
=
72
captureButton
.
height
=
72
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseFill
=
true
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
...
@@ -306,6 +306,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -306,6 +306,8 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
captureButton
.
shadowDepth
=
.
None
captureButton
.
shadowDepth
=
.
None
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
captureButton
)
view
.
addSubview
(
captureButton
)
captureView
.
captureButton
=
captureButton
}
}
/**
/**
...
@@ -318,11 +320,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -318,11 +320,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
cameraButton
.
setImage
(
img4
,
forState
:
.
Highlighted
)
cameraButton
.
setImage
(
img4
,
forState
:
.
Highlighted
)
cameraButton
.
addTarget
(
self
,
action
:
"handleCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
cameraButton
.
addTarget
(
self
,
action
:
"handleCameraButton:"
,
forControlEvents
:
.
TouchUpInside
)
view
.
addSubview
(
cameraButton
)
captureView
.
cameraButton
=
cameraButton
cameraButton
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomLeft
(
view
,
child
:
cameraButton
,
bottom
:
24
,
left
:
24
)
captureView
.
captureButton
=
cameraButton
}
}
/**
/**
...
@@ -335,10 +333,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -335,10 +333,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
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
)
captureView
.
videoButton
=
videoButton
captureView
.
videoButton
=
videoButton
}
}
...
...
Sources/CaptureView.swift
View file @
2685c8f6
...
@@ -19,6 +19,11 @@
...
@@ -19,6 +19,11 @@
import
UIKit
import
UIKit
import
AVFoundation
import
AVFoundation
public
enum
CaptureMode
{
case
Photo
case
Video
}
@objc(CaptureViewDelegate)
@objc(CaptureViewDelegate)
public
protocol
CaptureViewDelegate
:
MaterialDelegate
{
public
protocol
CaptureViewDelegate
:
MaterialDelegate
{
/**
/**
...
@@ -93,6 +98,24 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -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
:name: previewView
*/
*/
public
private(set)
lazy
var
previewView
:
CapturePreviewView
=
CapturePreviewView
()
public
private(set)
lazy
var
previewView
:
CapturePreviewView
=
CapturePreviewView
()
...
@@ -146,7 +169,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -146,7 +169,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
/**
:name: cameraButton
:name: cameraButton
*/
*/
public
var
cameraButton
:
MaterialButton
?
public
var
cameraButton
:
MaterialButton
?
{
didSet
{
cameraButton
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
/**
:name: captureButton
:name: captureButton
...
@@ -156,7 +184,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -156,7 +184,12 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
/**
:name: videoButton
:name: videoButton
*/
*/
public
var
videoButton
:
MaterialButton
?
public
var
videoButton
:
MaterialButton
?
{
didSet
{
videoButton
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
/**
:name: switchCameraButton
:name: switchCameraButton
...
@@ -169,11 +202,67 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -169,11 +202,67 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
public
var
flashButton
:
MaterialButton
?
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
:name: prepareView
*/
*/
public
override
func
prepareView
()
{
public
override
func
prepareView
()
{
super
.
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 {
...
@@ -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
(
previewView
.
layer
as!
AVCaptureVideoPreviewLayer
)
.
session
=
captureSession
.
session
captureSession
.
startSession
()
captureSession
.
startSession
()
addSubview
(
previewView
)
previewView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
self
,
child
:
previewView
)
}
}
/**
/**
...
@@ -299,7 +386,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -299,7 +386,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
*/
*/
private
func
prepareFocusView
()
{
private
func
prepareFocusView
()
{
if
let
v
:
MaterialView
=
focusView
{
if
let
v
:
MaterialView
=
focusView
{
addSubview
(
v
)
v
.
hidden
=
true
v
.
hidden
=
true
}
}
}
}
...
@@ -309,7 +395,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
...
@@ -309,7 +395,6 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
*/
*/
private
func
prepareExposureView
()
{
private
func
prepareExposureView
()
{
if
let
v
:
MaterialView
=
exposureView
{
if
let
v
:
MaterialView
=
exposureView
{
addSubview
(
v
)
v
.
hidden
=
true
v
.
hidden
=
true
}
}
}
}
...
...
Sources/MaterialTheme.swift
View file @
2685c8f6
...
@@ -208,9 +208,12 @@ public extension MaterialTheme.navigationBarView {
...
@@ -208,9 +208,12 @@ public extension MaterialTheme.navigationBarView {
// captureView
// captureView
public
extension
MaterialTheme
.
captureView
{
public
extension
MaterialTheme
.
captureView
{
// shadow
// shadow
public
static
var
shadowDepth
:
MaterialDepth
=
.
Depth2
public
static
var
shadowDepth
:
MaterialDepth
=
.
None
public
static
var
shadowColor
:
UIColor
=
MaterialColor
.
black
public
static
var
shadowColor
:
UIColor
=
MaterialColor
.
black
// shape
public
static
var
contentInsetsRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square4
)
// 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
...
@@ -221,6 +224,12 @@ public extension MaterialTheme.captureView {
...
@@ -221,6 +224,12 @@ public extension MaterialTheme.captureView {
// interaction
// interaction
public
static
var
userInteractionEnabled
:
Bool
=
true
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
// position
public
static
var
zPosition
:
CGFloat
=
0
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