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
4e2e0f24
Commit
4e2e0f24
authored
Nov 14, 2015
by
danieldahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated to latest
parent
9a2e6a45
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
187 additions
and
192 deletions
+187
-192
Source/BasicCollectionViewCell.swift
+7
-6
Source/MaterialButton.swift
+6
-6
Source/MaterialLayer.swift
+2
-2
Source/MaterialPanCollectionViewCell.swift
+35
-19
Source/MaterialPulseCollectionViewCell.swift
+4
-4
Source/MaterialPulseView.swift
+4
-4
Source/MaterialView.swift
+4
-4
Source/SideNavigationViewController.swift
+125
-147
No files found.
Source/BasicCollectionViewCell.swift
View file @
4e2e0f24
...
@@ -20,14 +20,14 @@ import UIKit
...
@@ -20,14 +20,14 @@ import UIKit
public
class
BasicCollectionViewCell
:
MaterialPanCollectionViewCell
{
public
class
BasicCollectionViewCell
:
MaterialPanCollectionViewCell
{
/**
/**
:name: titleLa
yer
:name: titleLa
bel
*/
*/
public
private(set)
lazy
var
titleLa
yer
:
MaterialTextLayer
=
MaterialTextLayer
()
public
private(set)
lazy
var
titleLa
bel
:
MaterialLabel
=
MaterialLabel
()
/**
/**
:name: detailLa
yer
:name: detailLa
bel
*/
*/
public
private(set)
lazy
var
detailLa
yer
:
MaterialTextLayer
=
MaterialTextLayer
()
public
private(set)
lazy
var
detailLa
bel
:
MaterialLabel
=
MaterialLabel
()
/**
/**
:name: prepareView
:name: prepareView
...
@@ -36,9 +36,9 @@ public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
...
@@ -36,9 +36,9 @@ public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
super
.
prepareView
()
super
.
prepareView
()
// title
// title
layer
.
addSublayer
(
titleLayer
)
addSubview
(
titleLabel
)
// detail
// detail
layer
.
addSublayer
(
detailLayer
)
addSubview
(
detailLabel
)
}
}
}
}
\ No newline at end of file
Source/MaterialButton.swift
View file @
4e2e0f24
...
@@ -364,9 +364,9 @@ public class MaterialButton : UIButton {
...
@@ -364,9 +364,9 @@ public class MaterialButton : UIButton {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
@@ -393,12 +393,12 @@ public class MaterialButton : UIButton {
...
@@ -393,12 +393,12 @@ public class MaterialButton : UIButton {
let
t
:
CFTimeInterval
=
0.25
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
r
/
d
self
.
pulseLayer
.
cornerRadius
=
r
/
d
}
)
}
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
1.5
*
d
,
duration
:
t
),
forKey
:
nil
)
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
1.5
*
d
,
duration
:
t
),
forKey
:
nil
)
}
}
...
@@ -416,9 +416,9 @@ public class MaterialButton : UIButton {
...
@@ -416,9 +416,9 @@ public class MaterialButton : UIButton {
if
spotlight
{
if
spotlight
{
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
if
layer
.
containsPoint
(
point
)
{
if
layer
.
containsPoint
(
point
)
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
position
=
point
}
)
}
}
}
}
}
}
}
...
...
Source/MaterialLayer.swift
View file @
4e2e0f24
...
@@ -254,9 +254,9 @@ public class MaterialLayer : CAShapeLayer {
...
@@ -254,9 +254,9 @@ public class MaterialLayer : CAShapeLayer {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
self
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
removeAnimationForKey
(
a
.
keyPath
!
)
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
Source/MaterialPanCollectionViewCell.swift
View file @
4e2e0f24
...
@@ -51,14 +51,14 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -51,14 +51,14 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
private
lazy
var
rightOnDragRelease
:
Bool
=
false
private
lazy
var
rightOnDragRelease
:
Bool
=
false
/**
/**
:name: left
Layer
:name: left
View
*/
*/
public
private(set)
lazy
var
left
Layer
:
MaterialLayer
=
MaterialLayer
()
public
private(set)
lazy
var
left
View
:
MaterialView
=
MaterialView
()
/**
/**
:name: right
Layer
:name: right
View
*/
*/
public
private(set)
lazy
var
right
Layer
:
MaterialLayer
=
MaterialLayer
()
public
private(set)
lazy
var
right
View
:
MaterialView
=
MaterialView
()
/**
/**
:name: revealed
:name: revealed
...
@@ -66,6 +66,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -66,6 +66,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
public
private(set)
lazy
var
revealed
:
Bool
=
false
public
private(set)
lazy
var
revealed
:
Bool
=
false
/**
/**
:name: closeAutomatically
*/
public
lazy
var
closeAutomatically
:
Bool
=
true
/**
:name: gestureRecognizerShouldBegin
:name: gestureRecognizerShouldBegin
*/
*/
public
override
func
gestureRecognizerShouldBegin
(
gestureRecognizer
:
UIGestureRecognizer
)
->
Bool
{
public
override
func
gestureRecognizerShouldBegin
(
gestureRecognizer
:
UIGestureRecognizer
)
->
Bool
{
...
@@ -94,8 +99,8 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -94,8 +99,8 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
borderColor
=
MaterialTheme
.
pulseCollectionView
.
bordercolor
borderColor
=
MaterialTheme
.
pulseCollectionView
.
bordercolor
masksToBounds
=
true
masksToBounds
=
true
prepareLeft
Layer
()
prepareLeft
View
()
prepareRight
Layer
()
prepareRight
View
()
preparePanGesture
()
preparePanGesture
()
}
}
...
@@ -117,20 +122,27 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -117,20 +122,27 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
}
}
}
}
/**
:name: close
*/
public
func
close
()
{
animation
(
MaterialAnimation
.
position
(
CGPointMake
(
width
/
2
,
y
+
height
/
2
),
duration
:
0.25
))
}
//
//
// :name: prepareLeft
Layer
// :name: prepareLeft
View
//
//
internal
func
prepareLeft
Layer
()
{
internal
func
prepareLeft
View
()
{
left
Layer
.
frame
=
CGRectMake
(
-
width
,
0
,
width
,
height
)
left
View
.
frame
=
CGRectMake
(
-
width
,
0
,
width
,
height
)
layer
.
addSublayer
(
leftLayer
)
addSubview
(
leftView
)
}
}
//
//
// :name: prepareRight
Layer
// :name: prepareRight
View
//
//
internal
func
prepareRight
Layer
()
{
internal
func
prepareRight
View
()
{
right
Layer
.
frame
=
CGRectMake
(
width
,
0
,
width
,
height
)
right
View
.
frame
=
CGRectMake
(
width
,
0
,
width
,
height
)
layer
.
addSublayer
(
rightLayer
)
addSubview
(
rightView
)
}
}
//
//
...
@@ -150,17 +162,17 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -150,17 +162,17 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case
.
Began
:
case
.
Began
:
originalPosition
=
position
originalPosition
=
position
masksToBounds
=
false
masksToBounds
=
false
rightOnDragRelease
=
x
<
-
width
/
2
leftOnDragRelease
=
x
>
width
/
2
leftOnDragRelease
=
x
>
width
/
2
rightOnDragRelease
=
x
<
-
width
/
2
case
.
Changed
:
case
.
Changed
:
let
translation
=
recognizer
.
translationInView
(
self
)
let
translation
=
recognizer
.
translationInView
(
self
)
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
self
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
}
)
}
rightOnDragRelease
=
x
<
-
width
/
2
leftOnDragRelease
=
x
>
width
/
2
leftOnDragRelease
=
x
>
width
/
2
rightOnDragRelease
=
x
<
-
width
/
2
if
!
revealed
&&
(
leftOnDragRelease
||
rightOnDragRelease
)
{
if
!
revealed
&&
(
leftOnDragRelease
||
rightOnDragRelease
)
{
revealed
=
true
revealed
=
true
...
@@ -180,7 +192,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
...
@@ -180,7 +192,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case
.
Ended
:
case
.
Ended
:
revealed
=
false
revealed
=
false
// snap back
// snap back
animation
(
MaterialAnimation
.
position
(
CGPointMake
(
width
/
2
,
y
+
height
/
2
),
duration
:
0.25
))
if
!
leftOnDragRelease
||
!
rightOnDragRelease
{
close
()
}
else
if
closeAutomatically
&&
(
leftOnDragRelease
||
rightOnDragRelease
)
{
close
()
}
default
:
break
default
:
break
}
}
...
...
Source/MaterialPulseCollectionViewCell.swift
View file @
4e2e0f24
...
@@ -385,9 +385,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
...
@@ -385,9 +385,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
@@ -411,9 +411,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
...
@@ -411,9 +411,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
let
t
:
CFTimeInterval
=
0.25
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
2
*
w
,
2
*
h
)
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
2
*
w
,
2
*
h
)
}
)
}
MaterialAnimation
.
animationWithDuration
(
t
,
animations
:
{
MaterialAnimation
.
animationWithDuration
(
t
,
animations
:
{
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
hidden
=
false
})
})
...
...
Source/MaterialPulseView.swift
View file @
4e2e0f24
...
@@ -84,12 +84,12 @@ public class MaterialPulseView : MaterialView {
...
@@ -84,12 +84,12 @@ public class MaterialPulseView : MaterialView {
let
t
:
CFTimeInterval
=
0.25
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
r
/
d
self
.
pulseLayer
.
cornerRadius
=
r
/
d
}
)
}
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
d
,
duration
:
t
),
forKey
:
nil
)
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
d
,
duration
:
t
),
forKey
:
nil
)
}
}
...
@@ -107,9 +107,9 @@ public class MaterialPulseView : MaterialView {
...
@@ -107,9 +107,9 @@ public class MaterialPulseView : MaterialView {
if
spotlight
{
if
spotlight
{
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
if
layer
.
containsPoint
(
point
)
{
if
layer
.
containsPoint
(
point
)
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
position
=
point
}
)
}
}
}
}
}
}
}
...
...
Source/MaterialView.swift
View file @
4e2e0f24
...
@@ -101,10 +101,10 @@ public class MaterialView : UIView {
...
@@ -101,10 +101,10 @@ public class MaterialView : UIView {
*/
*/
public
var
x
:
CGFloat
{
public
var
x
:
CGFloat
{
get
{
get
{
return
frame
.
origin
.
x
return
layer
.
frame
.
origin
.
x
}
}
set
(
value
)
{
set
(
value
)
{
frame
.
origin
.
x
=
value
layer
.
frame
.
origin
.
x
=
value
}
}
}
}
...
@@ -365,9 +365,9 @@ public class MaterialView : UIView {
...
@@ -365,9 +365,9 @@ public class MaterialView : UIView {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
Source/SideNavigationViewController.swift
View file @
4e2e0f24
...
@@ -39,17 +39,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -39,17 +39,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
//
// :name: originalPosition
// :name: originalPosition
//
//
private
var
originalPosition
:
CGPoint
!
private
lazy
var
originalPosition
:
CGPoint
=
CGPointZero
//
//
// :name:
left
PanGesture
// :name:
side
PanGesture
//
//
internal
var
left
PanGesture
:
UIPanGestureRecognizer
?
internal
var
side
PanGesture
:
UIPanGestureRecognizer
?
//
//
// :name:
left
TapGesture
// :name:
side
TapGesture
//
//
internal
var
left
TapGesture
:
UITapGestureRecognizer
?
internal
var
side
TapGesture
:
UITapGestureRecognizer
?
//
//
// :name: isViewBasedAppearance
// :name: isViewBasedAppearance
...
@@ -63,10 +63,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -63,10 +63,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
*/
public
var
userInteractionEnabled
:
Bool
{
public
var
userInteractionEnabled
:
Bool
{
get
{
get
{
return
mainViewController
!
.
view
.
userInteractionEnabled
return
mainViewController
.
view
.
userInteractionEnabled
}
}
set
(
value
)
{
set
(
value
)
{
mainViewController
!
.
view
.
userInteractionEnabled
=
value
mainViewController
.
view
.
userInteractionEnabled
=
value
}
}
}
}
...
@@ -114,31 +114,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -114,31 +114,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
/**
/**
:name:
isLeftContainerO
pened
:name:
o
pened
*/
*/
public
var
isLeftContainerO
pened
:
Bool
{
public
var
o
pened
:
Bool
{
return
leftView
?
.
x
!=
-
leftViewControllerWidth
return
sideView
.
position
.
x
==
sideViewControllerWidth
/
2
}
}
/**
/**
:name:
left
View
:name:
side
View
*/
*/
public
private(set)
var
leftView
:
MaterialView
?
public
private(set)
var
sideView
:
MaterialView
=
MaterialView
()
/**
/**
:name: maintViewController
:name: maintViewController
*/
*/
public
var
mainViewController
:
UIViewController
?
public
var
mainViewController
:
UIViewController
!
/**
/**
:name:
left
ViewController
:name:
side
ViewController
*/
*/
public
var
leftViewController
:
UIViewController
?
public
var
sideViewController
:
UIViewController
!
/**
/**
:name:
left
ViewControllerWidth
:name:
side
ViewControllerWidth
*/
*/
public
private(set)
var
leftViewControllerWidth
:
CGFloat
=
240
public
var
sideViewControllerWidth
:
CGFloat
=
240
{
didSet
{
horizontalThreshold
=
sideViewControllerWidth
/
2
layoutSideView
()
}
}
/**
/**
:name: init
:name: init
...
@@ -157,13 +162,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -157,13 +162,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
/**
:name: init
:name: init
*/
*/
public
convenience
init
(
mainViewController
:
UIViewController
,
left
ViewController
:
UIViewController
)
{
public
convenience
init
(
mainViewController
:
UIViewController
,
side
ViewController
:
UIViewController
)
{
self
.
init
()
self
.
init
()
self
.
mainViewController
=
mainViewController
self
.
mainViewController
=
mainViewController
self
.
leftViewController
=
left
ViewController
self
.
sideViewController
=
side
ViewController
prepareView
()
prepareView
()
prepareMainView
()
prepareLeftView
()
}
}
//
//
...
@@ -177,92 +180,56 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -177,92 +180,56 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
override
func
viewWillLayoutSubviews
()
{
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
super
.
viewWillLayoutSubviews
()
layoutBackdropLayer
()
layoutBackdropLayer
()
if
let
v
:
MaterialView
=
leftView
{
layoutSideView
()
leftViewController
?
.
view
.
frame
=
v
.
bounds
leftViewController
?
.
view
.
center
=
CGPointMake
(
v
.
width
/
2
,
v
.
height
/
2
)
}
}
}
/**
/**
:name:
setLeftViewControllerWidth
:name:
toggleSideViewContainer
*/
*/
public
func
setLeftViewControllerWidth
(
width
:
CGFloat
,
hidden
:
Bool
,
animated
:
Bool
)
{
public
func
toggleSideViewContainer
(
velocity
:
CGFloat
=
0
)
{
leftViewControllerWidth
=
width
opened
?
close
(
velocity
)
:
open
(
velocity
)
let
w
:
CGFloat
=
(
hidden
?
-
width
:
width
)
/
2
if
animated
{
MaterialAnimation
.
animationWithDuration
(
0.25
,
animations
:
{
self
.
leftView
!.
width
=
width
self
.
leftView
!.
position
.
x
=
w
})
{
self
.
userInteractionEnabled
=
false
}
}
else
{
MaterialAnimation
.
animationDisabled
({
self
.
leftView
!.
width
=
width
self
.
leftView
!.
position
.
x
=
w
})
}
}
}
/**
/**
:name:
toggleLeftViewContainer
:name:
open
*/
*/
public
func
toggleLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
public
func
open
(
velocity
:
CGFloat
=
0
)
{
isLeftContainerOpened
?
closeLeftViewContainer
(
velocity
)
:
openLeftViewContainer
(
velocity
)
toggleStatusBar
(
true
)
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
animations
:
{
self
.
sideView
.
position
.
x
=
self
.
sideViewControllerWidth
/
2
self
.
backdropLayer
.
hidden
=
false
})
{
self
.
userInteractionEnabled
=
false
}
}
}
/**
/**
:name:
openLeftViewContainer
:name:
close
*/
*/
public
func
openLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
public
func
close
(
velocity
:
CGFloat
=
0
)
{
if
let
v
=
leftView
{
toggleStatusBar
(
false
)
let
w
:
CGFloat
=
v
.
width
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
let
h
:
CGFloat
=
v
.
height
animations
:
{
let
d
:
Double
=
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
v
.
x
/
velocity
))))
self
.
sideView
.
position
.
x
=
-
self
.
sideViewControllerWidth
/
2
self
.
backdropLayer
.
hidden
=
true
toggleStatusBar
(
true
)
})
{
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
self
.
userInteractionEnabled
=
true
v
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
self
.
backdropLayer
.
hidden
=
false
})
{
self
.
userInteractionEnabled
=
false
}
}
}
}
}
/**
/**
:name:
closeLeftViewContain
er
:name:
gestureRecogniz
er
*/
*/
public
func
closeLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
if
let
v
=
leftView
{
let
w
:
CGFloat
=
v
.
width
let
h
:
CGFloat
=
v
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
v
.
x
/
velocity
))))
toggleStatusBar
(
false
)
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
v
.
position
=
CGPointMake
(
-
w
/
2
,
h
/
2
)
self
.
backdropLayer
.
hidden
=
true
})
{
self
.
userInteractionEnabled
=
true
}
}
}
//
// :name: gestureRecognizer
//
public
func
gestureRecognizer
(
gestureRecognizer
:
UIGestureRecognizer
,
shouldReceiveTouch
touch
:
UITouch
)
->
Bool
{
public
func
gestureRecognizer
(
gestureRecognizer
:
UIGestureRecognizer
,
shouldReceiveTouch
touch
:
UITouch
)
->
Bool
{
if
!
enabled
{
if
!
enabled
{
return
false
return
false
}
}
if
gestureRecognizer
==
left
PanGesture
{
if
gestureRecognizer
==
side
PanGesture
{
return
gesturePan
Left
ViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
return
gesturePan
Side
ViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
}
}
if
gestureRecognizer
==
left
TapGesture
{
if
gestureRecognizer
==
side
TapGesture
{
return
isLeftContainerOpened
&&
!
isPointContainedWithinViewController
(
leftView
!
,
point
:
touch
.
locationInView
(
view
))
return
opened
&&
!
isPointContainedWithinViewController
(
sideView
,
point
:
touch
.
locationInView
(
view
))
}
}
return
false
return
false
}
}
...
@@ -273,70 +240,79 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -273,70 +240,79 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
internal
func
prepareView
()
{
internal
func
prepareView
()
{
backdropColor
=
MaterialColor
.
black
backdropColor
=
MaterialColor
.
black
prepareBackdropLayer
()
prepareBackdropLayer
()
prepareMainView
()
prepareSideView
()
}
}
//
//
// :name: prepareMainView
// :name: prepareMainView
//
//
internal
func
prepareMainView
()
{
internal
func
prepareMainView
()
{
prepareViewControllerWithinContainer
(
mainViewController
!
,
container
:
view
)
prepareViewControllerWithinContainer
(
mainViewController
,
container
:
view
)
}
mainViewController
.
view
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
mainViewController
.
view
)
//
}
// :name: prepareLeftView
//
//
internal
func
prepareLeftView
()
{
// :name: prepareSideView
// container
//
leftView
=
MaterialView
(
frame
:
CGRectMake
(
0
,
0
,
leftViewControllerWidth
,
view
.
frame
.
height
))
internal
func
prepareSideView
()
{
leftView
!.
backgroundColor
=
MaterialColor
.
clear
MaterialAnimation
.
animationDisabled
{
view
.
addSubview
(
leftView
!
)
self
.
sideView
.
frame
=
CGRectMake
(
0
,
0
,
self
.
sideViewControllerWidth
,
self
.
view
.
bounds
.
height
)
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
MaterialAnimation
.
animationDisabled
({
}
self
.
leftView
!.
position
.
x
=
-
self
.
leftViewControllerWidth
/
2
sideView
.
backgroundColor
=
MaterialColor
.
blue
.
accent3
self
.
leftView
!.
zPosition
=
1000
sideView
.
zPosition
=
1000
})
view
.
addSubview
(
sideView
)
prepareViewControllerWithinContainer
(
leftViewController
!
,
container
:
leftView
!
)
// gestures
prepareLeftGestures
()
prepareLeftGestures
()
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
sideView
)
}
}
//
//
// :name:
handleLeftPanGesture
// :name:
layoutSideView
//
//
internal
func
handleLeftPanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
layoutSideView
()
{
if
let
v
=
leftView
{
MaterialAnimation
.
animationDisabled
{
switch
recognizer
.
state
{
self
.
sideView
.
width
=
self
.
sideViewControllerWidth
case
.
Began
:
self
.
sideView
.
height
=
self
.
view
.
bounds
.
height
originalPosition
=
v
.
position
self
.
sideView
.
position
=
CGPointMake
((
self
.
opened
?
1
:
-
1
)
*
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
toggleStatusBar
(
true
)
// self.sideViewController.view.frame = self.sideView.bounds
backdropLayer
.
hidden
=
false
}
case
.
Changed
:
}
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
v
)
let
w
:
CGFloat
=
v
.
width
//
MaterialAnimation
.
animationDisabled
({
// :name: handlePanGesture
v
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
//
})
internal
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
case
.
Ended
:
switch
recognizer
.
state
{
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
case
.
Began
:
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
toggleStatusBar
(
true
)
if
v
.
x
<=
CGFloat
(
floor
(
-
leftViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
originalPosition
=
sideView
.
position
closeLeftViewContainer
(
x
)
backdropLayer
.
hidden
=
false
}
else
{
case
.
Changed
:
openLeftViewContainer
(
x
)
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
view
)
}
let
x
:
CGFloat
=
self
.
sideViewControllerWidth
/
2
default
:
break
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
x
?
x
:
self
.
originalPosition
.
x
+
translation
.
x
}
case
.
Ended
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
if
sideView
.
x
<=
CGFloat
(
floor
(
-
sideViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
close
(
x
)
}
else
{
open
(
x
)
}
}
default
:
break
}
}
}
}
//
//
// :name: handle
Left
TapGesture
// :name: handleTapGesture
//
//
internal
func
handle
Left
TapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
handleTapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
let
_
=
leftView
{
if
opened
{
close
LeftViewContainer
()
close
()
}
}
}
}
...
@@ -360,12 +336,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -360,12 +336,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: removeGestures
// :name: removeGestures
//
//
private
func
removeGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
inout
tap
:
UITapGestureRecognizer
?)
{
private
func
removeGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
inout
tap
:
UITapGestureRecognizer
?)
{
if
let
g
=
pan
{
if
let
v
=
pan
{
view
.
removeGestureRecognizer
(
g
)
view
.
removeGestureRecognizer
(
v
)
v
.
delegate
=
nil
pan
=
nil
pan
=
nil
}
}
if
let
g
=
tap
{
if
let
v
=
tap
{
view
.
removeGestureRecognizer
(
g
)
view
.
removeGestureRecognizer
(
v
)
v
.
delegate
=
nil
tap
=
nil
tap
=
nil
}
}
}
}
...
@@ -397,17 +375,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -397,17 +375,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
//
//
// :name: gesturePan
Left
ViewController
// :name: gesturePan
Side
ViewController
//
//
private
func
gesturePan
Left
ViewController
(
gesture
:
UIGestureRecognizer
,
withTouchPoint
point
:
CGPoint
)
->
Bool
{
private
func
gesturePan
Side
ViewController
(
gesture
:
UIGestureRecognizer
,
withTouchPoint
point
:
CGPoint
)
->
Bool
{
return
isLeftContainerOpened
||
enabled
&&
isLeftPointContainedWithinRect
(
point
)
return
opened
||
enabled
&&
isPointContainedWithinHorizontalThreshold
(
point
)
}
}
//
//
// :name: is
LeftPointContainedWithinRect
// :name: is
PointContainedWithinHorizontalThreshold
//
//
private
func
is
LeftPointContainedWithinRect
(
point
:
CGPoint
)
->
Bool
{
private
func
is
PointContainedWithinHorizontalThreshold
(
point
:
CGPoint
)
->
Bool
{
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
frame
.
height
),
point
)
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
bounds
.
height
),
point
)
}
}
//
//
...
@@ -428,18 +406,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -428,18 +406,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: layoutBackdropLayer
// :name: layoutBackdropLayer
//
//
private
func
layoutBackdropLayer
()
{
private
func
layoutBackdropLayer
()
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
backdropLayer
.
frame
=
self
.
view
.
bounds
self
.
backdropLayer
.
frame
=
self
.
view
.
bounds
self
.
backdropLayer
.
zPosition
=
900
self
.
backdropLayer
.
zPosition
=
900
self
.
backdropLayer
.
hidden
=
true
self
.
backdropLayer
.
hidden
=
true
}
)
}
}
}
//
//
// :name: prepareViewControllerWithinContainer
// :name: prepareViewControllerWithinContainer
//
//
private
func
prepareViewControllerWithinContainer
(
controller
:
UIViewController
,
container
:
UIView
)
{
private
func
prepareViewControllerWithinContainer
(
controller
:
UIViewController
,
container
:
UIView
)
{
controller
.
view
.
clipsToBounds
=
true
addChildViewController
(
controller
)
addChildViewController
(
controller
)
container
.
addSubview
(
controller
.
view
)
container
.
addSubview
(
controller
.
view
)
controller
.
didMoveToParentViewController
(
self
)
controller
.
didMoveToParentViewController
(
self
)
...
@@ -449,7 +426,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -449,7 +426,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareLeftGestures
// :name: prepareLeftGestures
//
//
private
func
prepareLeftGestures
()
{
private
func
prepareLeftGestures
()
{
removeGestures
(
&
leftPanGesture
,
tap
:
&
left
TapGesture
)
removeGestures
(
&
sidePanGesture
,
tap
:
&
side
TapGesture
)
prepareGestures
(
&
leftPanGesture
,
panSelector
:
"handleLeftPanGesture:"
,
tap
:
&
leftTapGesture
,
tapSelector
:
"handleLeft
TapGesture:"
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handlePanGesture:"
,
tap
:
&
sideTapGesture
,
tapSelector
:
"handle
TapGesture:"
)
}
}
}
}
\ No newline at end of file
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