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
bfe9ed9f
Commit
bfe9ed9f
authored
Nov 14, 2015
by
danieldahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated SideNav animation
parent
66bba074
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
110 deletions
+108
-110
MaterialKit.xcodeproj/project.pbxproj
+0
-8
Source/SideNavigationViewController.swift
+108
-102
No files found.
MaterialKit.xcodeproj/project.pbxproj
View file @
bfe9ed9f
...
@@ -257,7 +257,6 @@
...
@@ -257,7 +257,6 @@
9693BF841BCB0DEE0087054A
/* Extensions */
,
9693BF841BCB0DEE0087054A
/* Extensions */
,
96B57D4C1B90AF6A00DE7BBB
/* Theme */
,
96B57D4C1B90AF6A00DE7BBB
/* Theme */
,
9AAC38521B89553800FE6B2D
/* Font */
,
9AAC38521B89553800FE6B2D
/* Font */
,
963C7A681BD4726900D175C5
/* Text */
,
65AD15E81BC05B0E0068AF9C
/* Layer */
,
65AD15E81BC05B0E0068AF9C
/* Layer */
,
65B965851B8BEEB00055B139
/* View */
,
65B965851B8BEEB00055B139
/* View */
,
965C17C21BC7258100B1059A
/* Navigation */
,
965C17C21BC7258100B1059A
/* Navigation */
,
...
@@ -297,13 +296,6 @@
...
@@ -297,13 +296,6 @@
name
=
"Supporting Files"
;
name
=
"Supporting Files"
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
};
};
963C7A681BD4726900D175C5
/* Text */
=
{
isa
=
PBXGroup
;
children
=
(
);
name
=
Text
;
sourceTree
=
"<group>"
;
};
964B17B21BBA445D002A9CA0
/* Layout */
=
{
964B17B21BBA445D002A9CA0
/* Layout */
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
...
...
Source/SideNavigationViewController.swift
View file @
bfe9ed9f
...
@@ -42,6 +42,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -42,6 +42,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private
lazy
var
originalPosition
:
CGPoint
=
CGPointZero
private
lazy
var
originalPosition
:
CGPoint
=
CGPointZero
//
//
// :name: sideView
//
private
lazy
var
sideView
:
MaterialView
=
MaterialView
()
//
// :name: sidePanGesture
// :name: sidePanGesture
//
//
internal
var
sidePanGesture
:
UIPanGestureRecognizer
?
internal
var
sidePanGesture
:
UIPanGestureRecognizer
?
...
@@ -117,15 +122,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -117,15 +122,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: opened
:name: opened
*/
*/
public
var
opened
:
Bool
{
public
var
opened
:
Bool
{
return
sideView
.
position
.
x
==
sideViewControllerWidth
/
2
return
sideView
.
x
!=
-
sideViewControllerWidth
}
}
/**
/**
:name: sideView
*/
public
private(set)
var
sideView
:
MaterialView
=
MaterialView
()
/**
:name: maintViewController
:name: maintViewController
*/
*/
public
var
mainViewController
:
UIViewController
!
public
var
mainViewController
:
UIViewController
!
...
@@ -138,26 +138,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -138,26 +138,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
/**
:name: sideViewControllerWidth
:name: sideViewControllerWidth
*/
*/
public
var
sideViewControllerWidth
:
CGFloat
=
240
{
public
private(set)
var
sideViewControllerWidth
:
CGFloat
=
240
didSet
{
horizontalThreshold
=
sideViewControllerWidth
/
2
layoutSideView
()
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
:name: init
*/
public
override
init
(
nibName
nibNameOrNil
:
String
?,
bundle
nibBundleOrNil
:
NSBundle
?)
{
super
.
init
(
nibName
:
nibNameOrNil
,
bundle
:
nibBundleOrNil
)
}
/**
/**
:name: init
:name: init
...
@@ -167,26 +148,57 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -167,26 +148,57 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self
.
mainViewController
=
mainViewController
self
.
mainViewController
=
mainViewController
self
.
sideViewController
=
sideViewController
self
.
sideViewController
=
sideViewController
prepareView
()
prepareView
()
prepareMainView
()
prepareSideView
()
}
}
/
/
/
**
//
:name: viewDidLoad
:name: viewDidLoad
/
/
*
/
public
override
func
viewDidLoad
()
{
public
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
edgesForExtendedLayout
=
.
None
edgesForExtendedLayout
=
.
None
}
}
/**
:name: viewWillLayoutSubviews
*/
public
override
func
viewWillLayoutSubviews
()
{
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
super
.
viewWillLayoutSubviews
()
layoutBackdropLayer
()
layoutBackdropLayer
()
layoutSideView
()
if
let
v
:
MaterialView
=
sideView
{
sideViewController
?
.
view
.
frame
=
v
.
bounds
sideViewController
?
.
view
.
center
=
CGPointMake
(
v
.
width
/
2
,
v
.
height
/
2
)
}
}
}
/**
/**
:name:
toggleSideViewContainer
:name:
setSideViewControllerWidth
*/
*/
public
func
toggleSideViewContainer
(
velocity
:
CGFloat
=
0
)
{
public
func
setSideViewControllerWidth
(
width
:
CGFloat
,
hidden
:
Bool
,
animated
:
Bool
)
{
sideViewControllerWidth
=
width
let
w
:
CGFloat
=
(
hidden
?
-
width
:
width
)
/
2
if
animated
{
MaterialAnimation
.
animationWithDuration
(
0.25
,
animations
:
{
self
.
sideView
.
width
=
width
self
.
sideView
.
position
.
x
=
w
})
{
self
.
userInteractionEnabled
=
false
}
}
else
{
MaterialAnimation
.
animationDisabled
({
self
.
sideView
.
width
=
width
self
.
sideView
.
position
.
x
=
w
})
}
}
/**
:name: toggle
*/
public
func
toggle
(
velocity
:
CGFloat
=
0
)
{
opened
?
close
(
velocity
)
:
open
(
velocity
)
opened
?
close
(
velocity
)
:
open
(
velocity
)
}
}
...
@@ -194,10 +206,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -194,10 +206,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: open
:name: open
*/
*/
public
func
open
(
velocity
:
CGFloat
=
0
)
{
public
func
open
(
velocity
:
CGFloat
=
0
)
{
let
w
:
CGFloat
=
sideView
.
width
let
h
:
CGFloat
=
sideView
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
))))
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
animations
:
{
self
.
sideView
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
self
.
sideView
.
position
.
x
=
self
.
sideViewControllerWidth
/
2
self
.
backdropLayer
.
hidden
=
false
self
.
backdropLayer
.
hidden
=
false
})
{
})
{
self
.
userInteractionEnabled
=
false
self
.
userInteractionEnabled
=
false
...
@@ -208,10 +223,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -208,10 +223,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: close
:name: close
*/
*/
public
func
close
(
velocity
:
CGFloat
=
0
)
{
public
func
close
(
velocity
:
CGFloat
=
0
)
{
let
w
:
CGFloat
=
sideView
.
width
let
h
:
CGFloat
=
sideView
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
))))
toggleStatusBar
(
false
)
toggleStatusBar
(
false
)
MaterialAnimation
.
animationWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
animations
:
{
self
.
sideView
.
position
=
CGPointMake
(
-
w
/
2
,
h
/
2
)
self
.
sideView
.
position
.
x
=
-
self
.
sideViewControllerWidth
/
2
self
.
backdropLayer
.
hidden
=
true
self
.
backdropLayer
.
hidden
=
true
})
{
})
{
self
.
userInteractionEnabled
=
true
self
.
userInteractionEnabled
=
true
...
@@ -234,14 +252,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -234,14 +252,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
return
false
return
false
}
}
/**
:name: prepareGestures
*/
private
func
prepareGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
panSelector
:
Selector
,
inout
tap
:
UITapGestureRecognizer
?,
tapSelector
:
Selector
)
{
if
nil
==
pan
{
pan
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
panSelector
)
pan
!.
delegate
=
self
view
.
addGestureRecognizer
(
pan
!
)
}
if
nil
==
tap
{
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
tapSelector
)
tap
!.
delegate
=
self
view
.
addGestureRecognizer
(
tap
!
)
}
}
//
//
// :name: prepareView
// :name: prepareView
//
//
internal
func
prepareView
()
{
internal
func
prepareView
()
{
backdropColor
=
MaterialColor
.
black
backdropColor
=
MaterialColor
.
black
prepareBackdropLayer
()
prepareBackdropLayer
()
prepareMainView
()
prepareSideView
()
}
}
//
//
...
@@ -249,53 +281,43 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -249,53 +281,43 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
//
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: prepareSideView
// :name: prepareSideView
//
//
internal
func
prepareSideView
()
{
internal
func
prepareSideView
()
{
MaterialAnimation
.
animationDisabled
{
// container
self
.
sideView
.
frame
=
CGRectMake
(
0
,
0
,
self
.
sideViewControllerWidth
,
self
.
view
.
bounds
.
height
)
sideView
.
frame
=
CGRectMake
(
0
,
0
,
sideViewControllerWidth
,
view
.
frame
.
height
)
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
}
sideView
.
backgroundColor
=
MaterialColor
.
blue
.
accent3
sideView
.
backgroundColor
=
MaterialColor
.
blue
.
accent3
sideView
.
zPosition
=
1000
view
.
addSubview
(
sideView
)
view
.
addSubview
(
sideView
)
prepareLeftGestures
()
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
sideView
)
}
//
MaterialAnimation
.
animationDisabled
({
// :name: layoutSideView
self
.
sideView
.
position
.
x
=
-
self
.
sideViewControllerWidth
/
2
//
self
.
sideView
.
zPosition
=
1000
internal
func
layoutSideView
()
{
})
MaterialAnimation
.
animationDisabled
{
self
.
sideView
.
width
=
self
.
sideViewControllerWidth
prepareViewControllerWithinContainer
(
sideViewController
!
,
container
:
sideView
)
self
.
sideView
.
height
=
self
.
view
.
bounds
.
height
self
.
sideView
.
position
=
CGPointMake
((
self
.
opened
?
1
:
-
1
)
*
self
.
sideViewControllerWidth
/
2
,
self
.
view
.
bounds
.
height
/
2
)
// gestures
self
.
sideViewController
.
view
.
frame
=
self
.
sideView
.
bounds
prepareGestures
()
self
.
sideViewController
.
view
.
center
=
CGPointMake
(
self
.
sideView
.
width
/
2
,
self
.
sideView
.
height
/
2
)
}
}
}
//
//
// :name: handlePanGesture
// :name: handle
Left
PanGesture
//
//
internal
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
handle
Left
PanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
switch
recognizer
.
state
{
switch
recognizer
.
state
{
case
.
Began
:
case
.
Began
:
toggleStatusBar
(
true
)
originalPosition
=
sideView
.
position
originalPosition
=
sideView
.
position
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
backdropLayer
.
hidden
=
false
case
.
Changed
:
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
v
iew
)
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
sideV
iew
)
let
x
:
CGFloat
=
self
.
sideViewControllerWidth
/
2
let
w
:
CGFloat
=
sideView
.
width
MaterialAnimation
.
animationDisabled
{
MaterialAnimation
.
animationDisabled
(
{
self
.
sideView
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
x
?
x
:
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
:
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
...
@@ -309,42 +331,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -309,42 +331,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
//
//
// :name: handleTapGesture
// :name: handle
Left
TapGesture
//
//
internal
func
handleTapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
internal
func
handle
Left
TapGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
opened
{
if
opened
{
close
()
close
()
}
}
}
}
//
//
// :name: prepareGestures
//
private
func
prepareGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
panSelector
:
Selector
,
inout
tap
:
UITapGestureRecognizer
?,
tapSelector
:
Selector
)
{
if
nil
==
pan
{
pan
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
panSelector
)
pan
!.
delegate
=
self
view
.
addGestureRecognizer
(
pan
!
)
}
if
nil
==
tap
{
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
tapSelector
)
tap
!.
delegate
=
self
view
.
addGestureRecognizer
(
tap
!
)
}
}
//
// :name: removeGestures
// :name: removeGestures
//
//
private
func
removeGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
inout
tap
:
UITapGestureRecognizer
?)
{
private
func
removeGestures
(
inout
pan
:
UIPanGestureRecognizer
?,
inout
tap
:
UITapGestureRecognizer
?)
{
if
let
v
=
pan
{
if
let
g
=
pan
{
view
.
removeGestureRecognizer
(
v
)
view
.
removeGestureRecognizer
(
g
)
v
.
delegate
=
nil
pan
=
nil
pan
=
nil
}
}
if
let
v
=
tap
{
if
let
g
=
tap
{
view
.
removeGestureRecognizer
(
v
)
view
.
removeGestureRecognizer
(
g
)
v
.
delegate
=
nil
tap
=
nil
tap
=
nil
}
}
}
}
...
@@ -379,14 +383,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -379,14 +383,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: gesturePanSideViewController
// :name: gesturePanSideViewController
//
//
private
func
gesturePanSideViewController
(
gesture
:
UIGestureRecognizer
,
withTouchPoint
point
:
CGPoint
)
->
Bool
{
private
func
gesturePanSideViewController
(
gesture
:
UIGestureRecognizer
,
withTouchPoint
point
:
CGPoint
)
->
Bool
{
return
opened
||
enabled
&&
is
PointContainedWithinHorizontalThreshold
(
point
)
return
opened
||
enabled
&&
is
LeftPointContainedWithinRect
(
point
)
}
}
//
//
// :name: is
PointContainedWithinHorizontalThreshold
// :name: is
LeftPointContainedWithinRect
//
//
private
func
is
PointContainedWithinHorizontalThreshold
(
point
:
CGPoint
)
->
Bool
{
private
func
is
LeftPointContainedWithinRect
(
point
:
CGPoint
)
->
Bool
{
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
bounds
.
height
),
point
)
return
CGRectContainsPoint
(
CGRectMake
(
0
,
0
,
horizontalThreshold
,
view
.
frame
.
height
),
point
)
}
}
//
//
...
@@ -407,27 +411,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -407,27 +411,28 @@ 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
)
}
}
//
//
// :name: prepare
Left
Gestures
// :name: prepareGestures
//
//
private
func
prepare
Left
Gestures
()
{
private
func
prepareGestures
()
{
removeGestures
(
&
sidePanGesture
,
tap
:
&
sideTapGesture
)
removeGestures
(
&
sidePanGesture
,
tap
:
&
sideTapGesture
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handle
PanGesture:"
,
tap
:
&
sideTapGesture
,
tapSelector
:
"handle
TapGesture:"
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handle
LeftPanGesture:"
,
tap
:
&
sideTapGesture
,
tapSelector
:
"handleLeft
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