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
4d0765c9
Commit
4d0765c9
authored
Nov 14, 2015
by
danieldahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete working copy of SideNav
parent
0029c656
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
24 deletions
+26
-24
Source/SideNavigationViewController.swift
+26
-24
No files found.
Source/SideNavigationViewController.swift
View file @
4d0765c9
...
@@ -78,7 +78,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -78,7 +78,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
/**
:name: horizontalThreshold
:name: horizontalThreshold
*/
*/
public
lazy
var
horizontalThreshold
:
CGFloat
=
64
public
lazy
var
horizontalThreshold
:
CGFloat
=
0
/**
/**
:name: animationDuration
:name: animationDuration
...
@@ -166,6 +166,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -166,6 +166,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
override
func
viewWillLayoutSubviews
()
{
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
super
.
viewWillLayoutSubviews
()
layoutBackdropLayer
()
layoutBackdropLayer
()
horizontalThreshold
=
sideViewControllerWidth
/
2
sideView
.
width
=
sideViewControllerWidth
sideView
.
height
=
view
.
bounds
.
height
sideView
.
height
=
view
.
bounds
.
height
sideViewController
.
view
.
frame
.
size
.
width
=
sideView
.
width
sideViewController
.
view
.
frame
.
size
.
width
=
sideView
.
width
sideViewController
.
view
.
frame
.
size
.
height
=
sideView
.
height
sideViewController
.
view
.
frame
.
size
.
height
=
sideView
.
height
...
@@ -188,10 +190,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -188,10 +190,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self
.
userInteractionEnabled
=
false
self
.
userInteractionEnabled
=
false
}
}
}
else
{
}
else
{
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
width
=
width
self
.
sideView
.
width
=
width
self
.
sideView
.
position
.
x
=
w
self
.
sideView
.
position
.
x
=
w
}
)
}
}
}
}
}
...
@@ -207,10 +209,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -207,10 +209,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
*/
public
func
open
(
velocity
:
CGFloat
=
0
)
{
public
func
open
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
animations
:
{
animations
:
{
self
.
sideView
.
position
=
CGPointMake
(
self
.
sideView
.
width
/
2
,
self
.
sideView
.
height
/
2
)
self
.
sideView
.
position
=
CGPointMake
(
self
.
sideView
.
width
/
2
,
self
.
sideView
.
height
/
2
)
self
.
backdropLayer
.
hidden
=
false
})
{
})
{
self
.
userInteractionEnabled
=
false
self
.
userInteractionEnabled
=
false
}
}
...
@@ -221,10 +223,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -221,10 +223,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
*/
public
func
close
(
velocity
:
CGFloat
=
0
)
{
public
func
close
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
false
)
toggleStatusBar
(
false
)
backdropLayer
.
hidden
=
true
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
animations
:
{
animations
:
{
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideView
.
width
/
2
,
self
.
sideView
.
height
/
2
)
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideView
.
width
/
2
,
self
.
sideView
.
height
/
2
)
self
.
backdropLayer
.
hidden
=
true
})
{
})
{
self
.
userInteractionEnabled
=
true
self
.
userInteractionEnabled
=
true
}
}
...
@@ -266,7 +268,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -266,7 +268,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareView
// :name: prepareView
//
//
internal
func
prepareView
()
{
internal
func
prepareView
()
{
backdropColor
=
MaterialColor
.
black
prepareBackdropLayer
()
prepareBackdropLayer
()
}
}
...
@@ -285,14 +286,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -285,14 +286,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
internal
func
prepareSideView
()
{
internal
func
prepareSideView
()
{
// container
// container
sideView
.
frame
=
CGRectMake
(
0
,
0
,
sideViewControllerWidth
,
view
.
frame
.
height
)
sideView
.
frame
=
CGRectMake
(
0
,
0
,
sideViewControllerWidth
,
view
.
frame
.
height
)
sideView
.
backgroundColor
=
MaterialColor
.
blue
.
accent3
sideView
.
backgroundColor
=
MaterialColor
.
clear
sideView
.
autoresizesSubviews
=
true
view
.
addSubview
(
sideView
)
view
.
addSubview
(
sideView
)
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
position
.
x
=
-
self
.
sideViewControllerWidth
/
2
self
.
sideView
.
position
.
x
=
-
self
.
sideViewControllerWidth
/
2
self
.
sideView
.
zPosition
=
1000
self
.
sideView
.
zPosition
=
1000
}
)
}
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
sideView
)
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
sideView
)
...
@@ -301,21 +301,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -301,21 +301,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
//
//
// :name: handle
Left
PanGesture
// :name: handlePanGesture
//
//
internal
func
handle
Left
PanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
switch
recognizer
.
state
{
switch
recognizer
.
state
{
case
.
Began
:
case
.
Began
:
backdropLayer
.
hidden
=
false
originalPosition
=
sideView
.
position
originalPosition
=
sideView
.
position
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
case
.
Changed
:
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
sideView
)
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
sideView
)
let
w
:
CGFloat
=
sideView
.
width
let
w
:
CGFloat
=
sideView
.
width
MaterialAnimation
.
animationDisabled
(
{
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
sideView
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
}
)
}
case
.
Ended
:
case
.
Ended
,
.
Cancelled
,
.
Failed
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
if
sideView
.
x
<=
CGFloat
(
floor
(
-
sideViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
if
sideView
.
x
<=
CGFloat
(
floor
(
-
sideViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
...
@@ -323,14 +323,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -323,14 +323,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
else
{
}
else
{
open
(
x
)
open
(
x
)
}
}
default
:
break
case
.
Possible
:
break
}
}
}
}
//
//
// :name: handle
Left
TapGesture
// :name: handleTapGesture
//
//
internal
func
handle
Left
TapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
handleTapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
opened
{
if
opened
{
close
()
close
()
}
}
...
@@ -401,6 +401,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -401,6 +401,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareBackdropLayer
// :name: prepareBackdropLayer
//
//
private
func
prepareBackdropLayer
()
{
private
func
prepareBackdropLayer
()
{
backdropColor
=
MaterialColor
.
black
backdropLayer
.
zPosition
=
900
backdropLayer
.
hidden
=
true
view
.
layer
.
addSublayer
(
backdropLayer
)
view
.
layer
.
addSublayer
(
backdropLayer
)
}
}
...
@@ -408,11 +411,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -408,11 +411,9 @@ 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
.
hidden
=
true
})
}
}
//
//
...
@@ -429,6 +430,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -429,6 +430,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
//
private
func
prepareGestures
()
{
private
func
prepareGestures
()
{
removeGestures
(
&
sidePanGesture
,
tap
:
&
sideTapGesture
)
removeGestures
(
&
sidePanGesture
,
tap
:
&
sideTapGesture
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handle
LeftPanGesture:"
,
tap
:
&
sideTapGesture
,
tapSelector
:
"handleLeft
TapGesture:"
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handle
PanGesture:"
,
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