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
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
...
...
@@ -36,9 +36,9 @@ public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
super
.
prepareView
()
// title
layer
.
addSublayer
(
titleLayer
)
addSubview
(
titleLabel
)
// 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 {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
@@ -393,12 +393,12 @@ public class MaterialButton : UIButton {
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
r
/
d
}
)
}
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
1.5
*
d
,
duration
:
t
),
forKey
:
nil
)
}
...
...
@@ -416,9 +416,9 @@ public class MaterialButton : UIButton {
if
spotlight
{
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
if
layer
.
containsPoint
(
point
)
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
position
=
point
}
)
}
}
}
}
...
...
Source/MaterialLayer.swift
View file @
4e2e0f24
...
...
@@ -254,9 +254,9 @@ public class MaterialLayer : CAShapeLayer {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
Source/MaterialPanCollectionViewCell.swift
View file @
4e2e0f24
...
...
@@ -51,14 +51,14 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
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
...
...
@@ -66,6 +66,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
public
private(set)
lazy
var
revealed
:
Bool
=
false
/**
:name: closeAutomatically
*/
public
lazy
var
closeAutomatically
:
Bool
=
true
/**
:name: gestureRecognizerShouldBegin
*/
public
override
func
gestureRecognizerShouldBegin
(
gestureRecognizer
:
UIGestureRecognizer
)
->
Bool
{
...
...
@@ -94,8 +99,8 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
borderColor
=
MaterialTheme
.
pulseCollectionView
.
bordercolor
masksToBounds
=
true
prepareLeft
Layer
()
prepareRight
Layer
()
prepareLeft
View
()
prepareRight
View
()
preparePanGesture
()
}
...
...
@@ -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
()
{
left
Layer
.
frame
=
CGRectMake
(
-
width
,
0
,
width
,
height
)
layer
.
addSublayer
(
leftLayer
)
internal
func
prepareLeft
View
()
{
left
View
.
frame
=
CGRectMake
(
-
width
,
0
,
width
,
height
)
addSubview
(
leftView
)
}
//
// :name: prepareRight
Layer
// :name: prepareRight
View
//
internal
func
prepareRight
Layer
()
{
right
Layer
.
frame
=
CGRectMake
(
width
,
0
,
width
,
height
)
layer
.
addSublayer
(
rightLayer
)
internal
func
prepareRight
View
()
{
right
View
.
frame
=
CGRectMake
(
width
,
0
,
width
,
height
)
addSubview
(
rightView
)
}
//
...
...
@@ -150,17 +162,17 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case
.
Began
:
originalPosition
=
position
masksToBounds
=
false
rightOnDragRelease
=
x
<
-
width
/
2
leftOnDragRelease
=
x
>
width
/
2
rightOnDragRelease
=
x
<
-
width
/
2
case
.
Changed
:
let
translation
=
recognizer
.
translationInView
(
self
)
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
}
)
}
rightOnDragRelease
=
x
<
-
width
/
2
leftOnDragRelease
=
x
>
width
/
2
rightOnDragRelease
=
x
<
-
width
/
2
if
!
revealed
&&
(
leftOnDragRelease
||
rightOnDragRelease
)
{
revealed
=
true
...
...
@@ -180,7 +192,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case
.
Ended
:
revealed
=
false
// 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
}
...
...
Source/MaterialPulseCollectionViewCell.swift
View file @
4e2e0f24
...
...
@@ -385,9 +385,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
@@ -411,9 +411,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
2
*
w
,
2
*
h
)
}
)
}
MaterialAnimation
.
animationWithDuration
(
t
,
animations
:
{
self
.
pulseLayer
.
hidden
=
false
})
...
...
Source/MaterialPulseView.swift
View file @
4e2e0f24
...
...
@@ -84,12 +84,12 @@ public class MaterialPulseView : MaterialView {
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
r
/
d
}
)
}
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
d
,
duration
:
t
),
forKey
:
nil
)
}
...
...
@@ -107,9 +107,9 @@ public class MaterialPulseView : MaterialView {
if
spotlight
{
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
if
layer
.
containsPoint
(
point
)
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
pulseLayer
.
position
=
point
}
)
}
}
}
}
...
...
Source/MaterialView.swift
View file @
4e2e0f24
...
...
@@ -101,10 +101,10 @@ public class MaterialView : UIView {
*/
public
var
x
:
CGFloat
{
get
{
return
frame
.
origin
.
x
return
layer
.
frame
.
origin
.
x
}
set
(
value
)
{
frame
.
origin
.
x
=
value
layer
.
frame
.
origin
.
x
=
value
}
}
...
...
@@ -365,9 +365,9 @@ public class MaterialView : UIView {
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
...
...
Source/SideNavigationViewController.swift
View file @
4e2e0f24
...
...
@@ -39,17 +39,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
// :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
...
...
@@ -63,10 +63,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
public
var
userInteractionEnabled
:
Bool
{
get
{
return
mainViewController
!
.
view
.
userInteractionEnabled
return
mainViewController
.
view
.
userInteractionEnabled
}
set
(
value
)
{
mainViewController
!
.
view
.
userInteractionEnabled
=
value
mainViewController
.
view
.
userInteractionEnabled
=
value
}
}
...
...
@@ -114,31 +114,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
:name:
isLeftContainerO
pened
:name:
o
pened
*/
public
var
isLeftContainerO
pened
:
Bool
{
return
leftView
?
.
x
!=
-
leftViewControllerWidth
public
var
o
pened
:
Bool
{
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
*/
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
...
...
@@ -157,13 +162,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
:name: init
*/
public
convenience
init
(
mainViewController
:
UIViewController
,
left
ViewController
:
UIViewController
)
{
public
convenience
init
(
mainViewController
:
UIViewController
,
side
ViewController
:
UIViewController
)
{
self
.
init
()
self
.
mainViewController
=
mainViewController
self
.
leftViewController
=
left
ViewController
self
.
sideViewController
=
side
ViewController
prepareView
()
prepareMainView
()
prepareLeftView
()
}
//
...
...
@@ -177,92 +180,56 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
layoutBackdropLayer
()
if
let
v
:
MaterialView
=
leftView
{
leftViewController
?
.
view
.
frame
=
v
.
bounds
leftViewController
?
.
view
.
center
=
CGPointMake
(
v
.
width
/
2
,
v
.
height
/
2
)
}
layoutSideView
()
}
/**
:name:
setLeftViewControllerWidth
:name:
toggleSideViewContainer
*/
public
func
setLeftViewControllerWidth
(
width
:
CGFloat
,
hidden
:
Bool
,
animated
:
Bool
)
{
leftViewControllerWidth
=
width
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
})
}
public
func
toggleSideViewContainer
(
velocity
:
CGFloat
=
0
)
{
opened
?
close
(
velocity
)
:
open
(
velocity
)
}
/**
:name:
toggleLeftViewContainer
:name:
open
*/
public
func
toggleLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
isLeftContainerOpened
?
closeLeftViewContainer
(
velocity
)
:
openLeftViewContainer
(
velocity
)
public
func
open
(
velocity
:
CGFloat
=
0
)
{
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
)
{
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
(
true
)
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
v
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
self
.
backdropLayer
.
hidden
=
false
})
{
self
.
userInteractionEnabled
=
false
}
public
func
close
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
false
)
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
=
true
})
{
self
.
userInteractionEnabled
=
true
}
}
/**
: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
{
if
!
enabled
{
return
false
}
if
gestureRecognizer
==
left
PanGesture
{
return
gesturePan
Left
ViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
if
gestureRecognizer
==
side
PanGesture
{
return
gesturePan
Side
ViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
}
if
gestureRecognizer
==
left
TapGesture
{
return
isLeftContainerOpened
&&
!
isPointContainedWithinViewController
(
leftView
!
,
point
:
touch
.
locationInView
(
view
))
if
gestureRecognizer
==
side
TapGesture
{
return
opened
&&
!
isPointContainedWithinViewController
(
sideView
,
point
:
touch
.
locationInView
(
view
))
}
return
false
}
...
...
@@ -273,70 +240,79 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
internal
func
prepareView
()
{
backdropColor
=
MaterialColor
.
black
prepareBackdropLayer
()
prepareMainView
()
prepareSideView
()
}
//
// :name: prepareMainView
//
internal
func
prepareMainView
()
{
prepareViewControllerWithinContainer
(
mainViewController
!
,
container
:
view
)
}
//
// :name: prepareLeftView
//
internal
func
prepareLeftView
()
{
// container
leftView
=
MaterialView
(
frame
:
CGRectMake
(
0
,
0
,
leftViewControllerWidth
,
view
.
frame
.
height
))
leftView
!.
backgroundColor
=
MaterialColor
.
clear
view
.
addSubview
(
leftView
!
)
MaterialAnimation
.
animationDisabled
({
self
.
leftView
!.
position
.
x
=
-
self
.
leftViewControllerWidth
/
2
self
.
leftView
!.
zPosition
=
1000
})
prepareViewControllerWithinContainer
(
leftViewController
!
,
container
:
leftView
!
)
// gestures
prepareViewControllerWithinContainer
(
mainViewController
,
container
:
view
)
mainViewController
.
view
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
mainViewController
.
view
)
}
//
// :name: prepareSideView
//
internal
func
prepareSideView
()
{
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
frame
=
CGRectMake
(
0
,
0
,
self
.
sideViewControllerWidth
,
self
.
view
.
bounds
.
height
)
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
}
sideView
.
backgroundColor
=
MaterialColor
.
blue
.
accent3
sideView
.
zPosition
=
1000
view
.
addSubview
(
sideView
)
prepareLeftGestures
()
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
sideView
)
}
//
// :name:
handleLeftPanGesture
// :name:
layoutSideView
//
internal
func
handleLeftPanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
let
v
=
leftView
{
switch
recognizer
.
state
{
case
.
Began
:
originalPosition
=
v
.
position
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
v
)
let
w
:
CGFloat
=
v
.
width
MaterialAnimation
.
animationDisabled
({
v
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
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
v
.
x
<=
CGFloat
(
floor
(
-
leftViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
closeLeftViewContainer
(
x
)
}
else
{
openLeftViewContainer
(
x
)
}
default
:
break
internal
func
layoutSideView
()
{
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
width
=
self
.
sideViewControllerWidth
self
.
sideView
.
height
=
self
.
view
.
bounds
.
height
self
.
sideView
.
position
=
CGPointMake
((
self
.
opened
?
1
:
-
1
)
*
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
// self.sideViewController.view.frame = self.sideView.bounds
}
}
//
// :name: handlePanGesture
//
internal
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
switch
recognizer
.
state
{
case
.
Began
:
toggleStatusBar
(
true
)
originalPosition
=
sideView
.
position
backdropLayer
.
hidden
=
false
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
view
)
let
x
:
CGFloat
=
self
.
sideViewControllerWidth
/
2
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
)
{
if
let
_
=
leftView
{
close
LeftViewContainer
()
internal
func
handleTapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
opened
{
close
()
}
}
...
...
@@ -360,12 +336,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: removeGestures
//
private
func
removeGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
inout
tap
:
UITapGestureRecognizer
?)
{
if
let
g
=
pan
{
view
.
removeGestureRecognizer
(
g
)
if
let
v
=
pan
{
view
.
removeGestureRecognizer
(
v
)
v
.
delegate
=
nil
pan
=
nil
}
if
let
g
=
tap
{
view
.
removeGestureRecognizer
(
g
)
if
let
v
=
tap
{
view
.
removeGestureRecognizer
(
v
)
v
.
delegate
=
nil
tap
=
nil
}
}
...
...
@@ -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
{
return
isLeftContainerOpened
||
enabled
&&
isLeftPointContainedWithinRect
(
point
)
private
func
gesturePan
Side
ViewController
(
gesture
:
UIGestureRecognizer
,
withTouchPoint
point
:
CGPoint
)
->
Bool
{
return
opened
||
enabled
&&
isPointContainedWithinHorizontalThreshold
(
point
)
}
//
// :name: is
LeftPointContainedWithinRect
// :name: is
PointContainedWithinHorizontalThreshold
//
private
func
is
LeftPointContainedWithinRect
(
point
:
CGPoint
)
->
Bool
{
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
frame
.
height
),
point
)
private
func
is
PointContainedWithinHorizontalThreshold
(
point
:
CGPoint
)
->
Bool
{
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
bounds
.
height
),
point
)
}
//
...
...
@@ -428,18 +406,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: layoutBackdropLayer
//
private
func
layoutBackdropLayer
()
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
backdropLayer
.
frame
=
self
.
view
.
bounds
self
.
backdropLayer
.
zPosition
=
900
self
.
backdropLayer
.
hidden
=
true
}
)
}
}
//
// :name: prepareViewControllerWithinContainer
//
private
func
prepareViewControllerWithinContainer
(
controller
:
UIViewController
,
container
:
UIView
)
{
controller
.
view
.
clipsToBounds
=
true
addChildViewController
(
controller
)
container
.
addSubview
(
controller
.
view
)
controller
.
didMoveToParentViewController
(
self
)
...
...
@@ -449,7 +426,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareLeftGestures
//
private
func
prepareLeftGestures
()
{
removeGestures
(
&
leftPanGesture
,
tap
:
&
left
TapGesture
)
prepareGestures
(
&
leftPanGesture
,
panSelector
:
"handleLeftPanGesture:"
,
tap
:
&
leftTapGesture
,
tapSelector
:
"handleLeft
TapGesture:"
)
removeGestures
(
&
sidePanGesture
,
tap
:
&
side
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