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
6f5aa6bc
Commit
6f5aa6bc
authored
Oct 15, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on SideNavigationViewController
parent
6c8ac863
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
95 deletions
+101
-95
Source/MaterialButton.swift
+1
-1
Source/SideNavigationViewController.swift
+100
-94
No files found.
Source/MaterialButton.swift
View file @
6f5aa6bc
...
@@ -399,7 +399,7 @@ public class MaterialButton : UIButton {
...
@@ -399,7 +399,7 @@ public class MaterialButton : UIButton {
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
:
1.5
*
d
,
duration
:
t
),
forKey
:
nil
)
}
}
if
pulseScale
{
if
pulseScale
{
...
...
Source/SideNavigationViewController.swift
View file @
6f5aa6bc
...
@@ -44,8 +44,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -44,8 +44,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
static
var
bezelHeight
:
CGFloat
=
48
public
static
var
bezelHeight
:
CGFloat
=
48
public
static
var
containerWidth
:
CGFloat
=
240
public
static
var
containerWidth
:
CGFloat
=
240
public
static
var
containerHeight
:
CGFloat
=
240
public
static
var
containerHeight
:
CGFloat
=
240
public
static
var
defaultAnimationDuration
:
CGFloat
=
0.25
public
static
var
threshold
:
CGFloat
=
48
public
static
var
panningEnabled
:
Bool
=
true
public
static
var
panningEnabled
:
Bool
=
true
}
}
...
@@ -53,21 +51,54 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -53,21 +51,54 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: options
:name: options
*/
*/
public
struct
options
{
public
struct
options
{
public
static
var
shadowOpacity
:
Float
=
0
public
static
var
shadowRadius
:
CGFloat
=
0
public
static
var
shadowOffset
:
CGSize
=
CGSizeZero
public
static
var
backdropScale
:
CGFloat
=
1
public
static
var
backdropOpacity
:
CGFloat
=
0.5
public
static
var
hideStatusBar
:
Bool
=
true
public
static
var
horizontalThreshold
:
CGFloat
=
defaultOptions
.
threshold
public
static
var
verticalThreshold
:
CGFloat
=
defaultOptions
.
threshold
public
static
var
backdropBackgroundColor
:
UIColor
=
MaterialColor
.
black
public
static
var
animationDuration
:
CGFloat
=
defaultOptions
.
defaultAnimationDuration
public
static
var
leftBezelWidth
:
CGFloat
=
defaultOptions
.
bezelWidth
public
static
var
leftBezelWidth
:
CGFloat
=
defaultOptions
.
bezelWidth
public
static
var
leftViewContainerWidth
:
CGFloat
=
defaultOptions
.
containerWidth
public
static
var
leftViewContainerWidth
:
CGFloat
=
defaultOptions
.
containerWidth
public
static
var
leftPanFromBezel
:
Bool
=
defaultOptions
.
panningEnabled
public
static
var
leftPanFromBezel
:
Bool
=
defaultOptions
.
panningEnabled
}
}
//
// :name: originalPosition
//
private
var
originalPosition
:
CGPoint
!
/**
:name: hideStatusBar
*/
public
lazy
var
hideStatusBar
:
Bool
=
true
/**
:name: horizontalThreshold
*/
public
static
let
horizontalThreshold
:
CGFloat
=
64
/**
:name: animationDuration
*/
public
static
let
animationDuration
:
CGFloat
=
0.25
/**
:name: backdropLayer
*/
public
private(set)
static
var
backdropLayer
:
CAShapeLayer
=
CAShapeLayer
()
/**
:name: backdropOpacity
*/
public
static
var
backdropOpacity
:
CGFloat
=
0.5
{
didSet
{
backdropLayer
.
backgroundColor
=
backdropColor
?
.
colorWithAlphaComponent
(
backdropOpacity
)
.
CGColor
}
}
/**
:name: backdropColor
*/
public
static
var
backdropColor
:
UIColor
?
{
didSet
{
backdropLayer
.
backgroundColor
=
backdropColor
?
.
colorWithAlphaComponent
(
backdropOpacity
)
.
CGColor
}
}
/**
/**
:name: isViewBasedAppearance
:name: isViewBasedAppearance
*/
*/
...
@@ -88,25 +119,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -88,25 +119,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
/**
:name: isUserInteractionEnabled
:name: isUserInteractionEnabled
*/
*/
public
var
isUserInteractionEnabled
:
Bool
{
public
private(set)
var
isUserInteractionEnabled
:
Bool
{
get
{
get
{
return
mainViewCont
ainer
!
.
userInteractionEnabled
return
mainViewCont
roller
!.
view
.
userInteractionEnabled
}
}
set
(
value
)
{
set
(
value
)
{
mainViewCont
ainer
?
.
userInteractionEnabled
=
value
mainViewCont
roller
!.
view
.
userInteractionEnabled
=
value
}
}
}
}
//
// :name: originalPosition
//
private
var
originalPosition
:
CGPoint
!
/**
:name: backdropLayer
*/
public
private(set)
lazy
var
backdropLayer
:
MaterialLayer
=
MaterialLayer
()
/**
/**
:name: mainViewContainer
:name: mainViewContainer
*/
*/
...
@@ -197,7 +218,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -197,7 +218,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
override
func
viewWillLayoutSubviews
()
{
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
super
.
viewWillLayoutSubviews
()
if
nil
!=
mainViewController
{
if
nil
!=
mainViewController
{
prepareContainedViewController
(
&
mainViewCont
ainer
,
viewController
:
&
mainViewCont
roller
)
prepareContainedViewController
(
&
mainViewController
)
}
}
if
nil
!=
leftViewController
{
if
nil
!=
leftViewController
{
...
@@ -213,45 +234,40 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -213,45 +234,40 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
/**
/**
:name: openLeftViewContainer
:name: openLeftViewContainer
*/
*/
public
func
openLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
public
func
openLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
if
let
vc
=
leftViewContainer
{
if
let
vc
=
leftViewContainer
{
let
w
:
CGFloat
=
vc
.
width
let
w
:
CGFloat
=
vc
.
width
let
h
:
CGFloat
=
vc
.
height
let
h
:
CGFloat
=
vc
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
options
.
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
vc
.
frame
.
origin
.
x
/
velocity
))))
let
d
:
Double
=
Double
(
0
==
velocity
?
SideNavigationViewController
.
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
vc
.
frame
.
origin
.
x
/
velocity
))))
vc
.
shadowDepth
=
.
None
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
vc
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
vc
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
self
.
backdropLayer
.
opacity
=
Float
(
options
.
backdropOpacity
)
})
{
})
{
SideNavigationViewController
.
backdropLayer
.
hidden
=
false
self
.
isUserInteractionEnabled
=
false
self
.
isUserInteractionEnabled
=
false
// vc.shadowDepth = .Depth2
self
.
toggleStatusBar
(
true
)
}
}
}
}
/**
:name: closeLeftViewContainer
*/
public
func
closeLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
if
let
vc
=
leftViewContainer
{
let
w
:
CGFloat
=
vc
.
width
let
h
:
CGFloat
=
vc
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
SideNavigationViewController
.
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
vc
.
frame
.
origin
.
x
/
velocity
))))
// print(vc.frame)
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
// let a: CABasicAnimation = MaterialAnimation.position(CGPointMake(w / 2, h / 2), duration: d)
vc
.
position
=
CGPointMake
(
-
w
/
2
,
h
/
2
)
// a.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
})
{
// vc.animation(a)
SideNavigationViewController
.
backdropLayer
.
hidden
=
true
//
self
.
isUserInteractionEnabled
=
true
////
self
.
toggleStatusBar
(
false
)
// UIView.animateWithDuration(d,
}
// delay: 0,
// options: .CurveEaseInOut,
// animations: { _ in
// vc.frame.origin.x = 0
// self.backdropViewContainer?.layer.opacity = Float(options.backdropOpacity)
// self.mainViewContainer?.transform = CGAffineTransformMakeScale(options.backdropScale, options.backdropScale)
// }
// ) { _ in
// self.isUserInteractionEnabled = false
// }
// c.state = .Opened
// delegate?.sideNavDidOpenLeftViewContainer?(self, container: c)
}
}
}
}
...
@@ -272,8 +288,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -272,8 +288,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareView
// :name: prepareView
//
//
internal
func
prepareView
()
{
internal
func
prepareView
()
{
prepareMainContainer
()
SideNavigationViewController
.
backdropColor
=
MaterialColor
.
black
prepareBackdrop
Contain
er
()
prepareBackdrop
Lay
er
()
}
}
//
//
...
@@ -285,9 +301,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -285,9 +301,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
//
//
// :name:
add
Gestures
// :name:
prepare
Gestures
//
//
private
func
add
Gestures
(
inout
pan
:
UIPanGestureRecognizer
?,
panSelector
:
Selector
,
inout
tap
:
UITapGestureRecognizer
?,
tapSelector
:
Selector
)
{
private
func
prepare
Gestures
(
inout
pan
:
UIPanGestureRecognizer
?,
panSelector
:
Selector
,
inout
tap
:
UITapGestureRecognizer
?,
tapSelector
:
Selector
)
{
if
nil
==
pan
{
if
nil
==
pan
{
pan
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
panSelector
)
pan
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
panSelector
)
pan
!.
delegate
=
self
pan
!.
delegate
=
self
...
@@ -323,23 +339,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -323,23 +339,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
case
.
Began
:
case
.
Began
:
originalPosition
=
vc
.
position
originalPosition
=
vc
.
position
toggleStatusBar
(
true
)
toggleStatusBar
(
true
)
SideNavigationViewController
.
backdropLayer
.
hidden
=
false
case
.
Changed
:
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
vc
)
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
vc
)
let
w
:
CGFloat
=
leftViewContainer
!.
width
let
w
:
CGFloat
=
leftViewContainer
!.
width
MaterialAnimation
.
animationDisabled
({
MaterialAnimation
.
animationDisabled
({
vc
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
vc
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
backdropLayer
.
opacity
=
Float
(
vc
.
position
.
x
/
(
w
/
2
))
/
2
})
})
case
.
Ended
:
case
.
Ended
:
self
.
isUserInteractionEnabled
=
false
// snap back
// snap back
let
a
:
CABasicAnimation
=
MaterialAnimation
.
position
(
CGPointMake
(
vc
.
width
/
2
,
vc
.
height
/
2
),
duration
:
0.25
)
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
vc
)
a
.
timingFunction
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
if
SideNavigationViewController
.
horizontalThreshold
<=
translation
.
x
{
vc
.
animation
(
a
)
openLeftViewContainer
(
recognizer
.
velocityInView
(
self
.
view
)
.
x
)
}
else
{
break
closeLeftViewContainer
(
recognizer
.
velocityInView
(
self
.
view
)
.
x
)
}
default
:
break
default
:
break
}
}
}
}
...
@@ -356,7 +370,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -356,7 +370,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: toggleStatusBar
// :name: toggleStatusBar
//
//
private
func
toggleStatusBar
(
hide
:
Bool
=
false
)
{
private
func
toggleStatusBar
(
hide
:
Bool
=
false
)
{
if
options
.
hideStatusBar
{
if
hideStatusBar
{
if
isViewBasedAppearance
{
if
isViewBasedAppearance
{
UIApplication
.
sharedApplication
()
.
setStatusBarHidden
(
hide
,
withAnimation
:
.
Slide
)
UIApplication
.
sharedApplication
()
.
setStatusBarHidden
(
hide
,
withAnimation
:
.
Slide
)
}
else
{
}
else
{
...
@@ -405,23 +419,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -405,23 +419,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
}
//
//
// :name: prepare
MainContain
er
// :name: prepare
BackdropLay
er
//
//
private
func
prepareMainContainer
()
{
private
func
prepareBackdropLayer
()
{
mainViewContainer
=
MaterialView
(
frame
:
view
.
bounds
)
MaterialAnimation
.
animationDisabled
({
mainViewContainer
!.
backgroundColor
=
MaterialColor
.
clear
SideNavigationViewController
.
backdropLayer
.
frame
=
self
.
view
.
bounds
mainViewContainer
!.
autoresizingMask
=
[
.
FlexibleHeight
,
.
FlexibleWidth
]
SideNavigationViewController
.
backdropLayer
.
zPosition
=
900
view
.
addSubview
(
mainViewContainer
!
)
SideNavigationViewController
.
backdropLayer
.
hidden
=
true
}
})
view
.
layer
.
addSublayer
(
SideNavigationViewController
.
backdropLayer
)
//
// :name: prepareBackdropContainer
//
private
func
prepareBackdropContainer
()
{
backdropLayer
.
frame
=
view
.
bounds
backdropLayer
.
backgroundColor
=
options
.
backdropBackgroundColor
.
CGColor
backdropLayer
.
opacity
=
0
view
.
layer
.
addSublayer
(
backdropLayer
)
}
}
//
//
...
@@ -429,7 +435,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -429,7 +435,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
//
private
func
prepareLeftGestures
()
{
private
func
prepareLeftGestures
()
{
removeGestures
(
&
leftPanGesture
,
tap
:
&
leftTapGesture
)
removeGestures
(
&
leftPanGesture
,
tap
:
&
leftTapGesture
)
add
Gestures
(
&
leftPanGesture
,
panSelector
:
"handleLeftPanGesture:"
,
tap
:
&
leftTapGesture
,
tapSelector
:
"handleLeftTapGesture:"
)
prepare
Gestures
(
&
leftPanGesture
,
panSelector
:
"handleLeftPanGesture:"
,
tap
:
&
leftTapGesture
,
tapSelector
:
"handleLeftTapGesture:"
)
}
}
//
//
...
@@ -439,20 +445,19 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
...
@@ -439,20 +445,19 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
viewContainer
=
MaterialView
(
frame
:
CGRectMake
(
originX
,
originY
,
width
,
height
))
viewContainer
=
MaterialView
(
frame
:
CGRectMake
(
originX
,
originY
,
width
,
height
))
viewContainer
!.
backgroundColor
=
MaterialColor
.
red
.
base
viewContainer
!.
backgroundColor
=
MaterialColor
.
red
.
base
viewContainer
!.
autoresizingMask
=
[
.
FlexibleHeight
,
.
FlexibleWidth
]
viewContainer
!.
autoresizingMask
=
[
.
FlexibleHeight
,
.
FlexibleWidth
]
viewContainer
!.
zPosition
=
1000
view
.
addSubview
(
viewContainer
!
)
view
.
addSubview
(
viewContainer
!
)
}
}
//
//
// :name: prepareContainedViewController
// :name: prepareContainedViewController
//
//
private
func
prepareContainedViewController
(
inout
viewCont
ainer
:
MaterialView
?,
inout
viewCont
roller
:
UIViewController
?)
{
private
func
prepareContainedViewController
(
inout
viewController
:
UIViewController
?)
{
if
let
vc
=
viewController
{
if
let
vc
=
viewController
{
if
let
c
=
viewContainer
{
addChildViewController
(
vc
)
addChildViewController
(
vc
)
vc
.
view
.
frame
=
view
.
frame
vc
.
view
.
frame
=
c
.
frame
view
.
addSubview
(
vc
.
view
)
c
.
addSubview
(
vc
.
view
)
vc
.
didMoveToParentViewController
(
self
)
vc
.
didMoveToParentViewController
(
self
)
}
}
}
}
}
}
}
\ 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