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
4890abd4
Commit
4890abd4
authored
Nov 15, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added delegation to SideNavigationViewController
parent
ba4a0c46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
3 deletions
+64
-3
Source/SideNavigationViewController.swift
+64
-3
No files found.
Source/SideNavigationViewController.swift
View file @
4890abd4
...
@@ -34,6 +34,49 @@ public extension UIViewController {
...
@@ -34,6 +34,49 @@ public extension UIViewController {
}
}
}
}
@objc(SideNavigationViewDelegate)
public
protocol
SideNavigationViewDelegate
{
/**
:name: sideNavigationViewWillOpen
*/
optional
func
sideNavigationViewWillOpen
(
sideNavigationViewController
:
SideNavigationViewController
)
/**
:name: sideNavigationViewDidOpen
*/
optional
func
sideNavigationViewDidOpen
(
sideNavigationViewController
:
SideNavigationViewController
)
/**
:name: sideNavigationViewWillClose
*/
optional
func
sideNavigationViewWillClose
(
sideNavigationViewController
:
SideNavigationViewController
)
/**
:name: sideNavigationViewDidClose
*/
optional
func
sideNavigationViewDidClose
(
sideNavigationViewController
:
SideNavigationViewController
)
/**
:name: sideNavigationViewPanDidBegin
*/
optional
func
sideNavigationViewPanDidBegin
(
sideNavigationViewController
:
SideNavigationViewController
,
point
:
CGPoint
)
/**
:name: sideNavigationViewPanDidChange
*/
optional
func
sideNavigationViewPanDidChange
(
sideNavigationViewController
:
SideNavigationViewController
,
point
:
CGPoint
)
/**
:name: sideNavigationViewPanDidEnd
*/
optional
func
sideNavigationViewPanDidEnd
(
sideNavigationViewController
:
SideNavigationViewController
,
point
:
CGPoint
)
/**
:name: sideNavigationViewDidTap
*/
optional
func
sideNavigationViewDidTap
(
sideNavigationViewController
:
SideNavigationViewController
,
point
:
CGPoint
)
}
@objc(SideNavigationViewController)
@objc(SideNavigationViewController)
public
class
SideNavigationViewController
:
UIViewController
,
UIGestureRecognizerDelegate
{
public
class
SideNavigationViewController
:
UIViewController
,
UIGestureRecognizerDelegate
{
//
//
...
@@ -59,6 +102,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -59,6 +102,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
/**
/**
:name: delegate
*/
public
weak
var
delegate
:
SideNavigationViewDelegate
?
/**
:name: userInteractionEnabled
:name: userInteractionEnabled
*/
*/
public
var
userInteractionEnabled
:
Bool
{
public
var
userInteractionEnabled
:
Bool
{
...
@@ -201,7 +249,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -201,7 +249,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self
.
sideView
.
width
=
width
self
.
sideView
.
width
=
width
self
.
sideView
.
position
.
x
=
w
self
.
sideView
.
position
.
x
=
w
})
{
})
{
self
.
userInteractionEnabled
=
false
self
.
userInteractionEnabled
=
false
}
}
}
else
{
}
else
{
MaterialAnimation
.
animationDisabled
{
MaterialAnimation
.
animationDisabled
{
...
@@ -224,6 +272,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -224,6 +272,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
func
open
(
velocity
:
CGFloat
=
0
)
{
public
func
open
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
backdropLayer
.
hidden
=
false
backdropLayer
.
hidden
=
false
delegate
?
.
sideNavigationViewWillOpen
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animateWithDuration
(
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
)
...
@@ -232,6 +281,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -232,6 +281,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if
self
.
enableShadowDepth
{
if
self
.
enableShadowDepth
{
self
.
sideView
.
shadowDepth
=
self
.
shadowDepth
self
.
sideView
.
shadowDepth
=
self
.
shadowDepth
}
}
self
.
delegate
?
.
sideNavigationViewDidOpen
?(
self
)
}
}
}
}
...
@@ -241,6 +291,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -241,6 +291,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
func
close
(
velocity
:
CGFloat
=
0
)
{
public
func
close
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
false
)
toggleStatusBar
(
false
)
backdropLayer
.
hidden
=
true
backdropLayer
.
hidden
=
true
delegate
?
.
sideNavigationViewWillClose
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
sideView
.
x
/
velocity
)))),
MaterialAnimation
.
animateWithDuration
(
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
)
...
@@ -249,6 +300,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -249,6 +300,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if
self
.
enableShadowDepth
{
if
self
.
enableShadowDepth
{
self
.
sideView
.
shadowDepth
=
.
None
self
.
sideView
.
shadowDepth
=
.
None
}
}
self
.
delegate
?
.
sideNavigationViewDidClose
?(
self
)
}
}
}
}
...
@@ -262,8 +314,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -262,8 +314,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if
gestureRecognizer
==
sidePanGesture
{
if
gestureRecognizer
==
sidePanGesture
{
return
gesturePanSideViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
return
gesturePanSideViewController
(
gestureRecognizer
,
withTouchPoint
:
touch
.
locationInView
(
view
))
}
}
if
gestureRecognizer
==
sideTapGesture
{
if
gestureRecognizer
==
sideTapGesture
&&
opened
{
return
opened
&&
!
isPointContainedWithinViewController
(
sideView
,
point
:
touch
.
locationInView
(
view
))
let
point
:
CGPoint
=
touch
.
locationInView
(
view
)
delegate
?
.
sideNavigationViewDidTap
?(
self
,
point
:
point
)
return
!
isPointContainedWithinViewController
(
sideView
,
point
:
point
)
}
}
return
false
return
false
}
}
...
@@ -332,15 +386,22 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -332,15 +386,22 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer
.
hidden
=
false
backdropLayer
.
hidden
=
false
originalPosition
=
sideView
.
position
originalPosition
=
sideView
.
position
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
sideView
.
position
)
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
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
self
.
sideView
.
position
)
}
}
case
.
Ended
,
.
Cancelled
,
.
Failed
:
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
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
sideView
.
position
)
if
sideView
.
x
<=
CGFloat
(
floor
(
-
sideViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
if
sideView
.
x
<=
CGFloat
(
floor
(
-
sideViewControllerWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
close
(
x
)
close
(
x
)
}
else
{
}
else
{
...
...
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