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 {
self
.
pulseLayer
.
position
=
point
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
{
...
...
Source/SideNavigationViewController.swift
View file @
6f5aa6bc
...
...
@@ -44,8 +44,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
static
var
bezelHeight
:
CGFloat
=
48
public
static
var
containerWidth
:
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
}
...
...
@@ -53,21 +51,54 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: 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
leftViewContainerWidth
:
CGFloat
=
defaultOptions
.
containerWidth
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
*/
...
...
@@ -88,25 +119,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
:name: isUserInteractionEnabled
*/
public
var
isUserInteractionEnabled
:
Bool
{
public
private(set)
var
isUserInteractionEnabled
:
Bool
{
get
{
return
mainViewCont
ainer
!
.
userInteractionEnabled
return
mainViewCont
roller
!.
view
.
userInteractionEnabled
}
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
*/
...
...
@@ -197,7 +218,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
if
nil
!=
mainViewController
{
prepareContainedViewController
(
&
mainViewCont
ainer
,
viewController
:
&
mainViewCont
roller
)
prepareContainedViewController
(
&
mainViewController
)
}
if
nil
!=
leftViewController
{
...
...
@@ -213,45 +234,40 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
:name: openLeftViewContainer
:name: openLeftViewContainer
*/
public
func
openLeftViewContainer
(
velocity
:
CGFloat
=
0
)
{
if
let
vc
=
leftViewContainer
{
let
w
:
CGFloat
=
vc
.
width
let
h
:
CGFloat
=
vc
.
height
let
d
:
Double
=
Double
(
0
==
velocity
?
options
.
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
vc
.
frame
.
origin
.
x
/
velocity
))))
vc
.
shadowDepth
=
.
None
let
d
:
Double
=
Double
(
0
==
velocity
?
SideNavigationViewController
.
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
vc
.
frame
.
origin
.
x
/
velocity
))))
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
vc
.
position
=
CGPointMake
(
w
/
2
,
h
/
2
)
self
.
backdropLayer
.
opacity
=
Float
(
options
.
backdropOpacity
)
})
{
self
.
isUserInteractionEnabled
=
false
// vc.shadowDepth = .Depth2
})
{
SideNavigationViewController
.
backdropLayer
.
hidden
=
false
self
.
isUserInteractionEnabled
=
false
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)
// let a: CABasicAnimation = MaterialAnimation.position(CGPointMake(w / 2, h / 2), duration: d)
// a.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
// vc.animation(a)
//
////
// 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)
MaterialAnimation
.
animationWithDuration
(
d
,
animations
:
{
vc
.
position
=
CGPointMake
(
-
w
/
2
,
h
/
2
)
})
{
SideNavigationViewController
.
backdropLayer
.
hidden
=
true
self
.
isUserInteractionEnabled
=
true
self
.
toggleStatusBar
(
false
)
}
}
}
...
...
@@ -272,8 +288,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareView
//
internal
func
prepareView
()
{
prepareMainContainer
()
prepareBackdrop
Contain
er
()
SideNavigationViewController
.
backdropColor
=
MaterialColor
.
black
prepareBackdrop
Lay
er
()
}
//
...
...
@@ -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
{
pan
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
panSelector
)
pan
!.
delegate
=
self
...
...
@@ -323,23 +339,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
case
.
Began
:
originalPosition
=
vc
.
position
toggleStatusBar
(
true
)
SideNavigationViewController
.
backdropLayer
.
hidden
=
false
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
vc
)
let
w
:
CGFloat
=
leftViewContainer
!.
width
MaterialAnimation
.
animationDisabled
({
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
:
self
.
isUserInteractionEnabled
=
false
// snap back
let
a
:
CABasicAnimation
=
MaterialAnimation
.
position
(
CGPointMake
(
vc
.
width
/
2
,
vc
.
height
/
2
),
duration
:
0.25
)
a
.
timingFunction
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
vc
.
animation
(
a
)
break
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
vc
)
if
SideNavigationViewController
.
horizontalThreshold
<=
translation
.
x
{
openLeftViewContainer
(
recognizer
.
velocityInView
(
self
.
view
)
.
x
)
}
else
{
closeLeftViewContainer
(
recognizer
.
velocityInView
(
self
.
view
)
.
x
)
}
default
:
break
}
}
...
...
@@ -356,7 +370,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: toggleStatusBar
//
private
func
toggleStatusBar
(
hide
:
Bool
=
false
)
{
if
options
.
hideStatusBar
{
if
hideStatusBar
{
if
isViewBasedAppearance
{
UIApplication
.
sharedApplication
()
.
setStatusBarHidden
(
hide
,
withAnimation
:
.
Slide
)
}
else
{
...
...
@@ -405,23 +419,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
//
// :name: prepare
MainContain
er
// :name: prepare
BackdropLay
er
//
private
func
prepareMainContainer
()
{
mainViewContainer
=
MaterialView
(
frame
:
view
.
bounds
)
mainViewContainer
!.
backgroundColor
=
MaterialColor
.
clear
mainViewContainer
!.
autoresizingMask
=
[
.
FlexibleHeight
,
.
FlexibleWidth
]
view
.
addSubview
(
mainViewContainer
!
)
}
//
// :name: prepareBackdropContainer
//
private
func
prepareBackdropContainer
()
{
backdropLayer
.
frame
=
view
.
bounds
backdropLayer
.
backgroundColor
=
options
.
backdropBackgroundColor
.
CGColor
backdropLayer
.
opacity
=
0
view
.
layer
.
addSublayer
(
backdropLayer
)
private
func
prepareBackdropLayer
()
{
MaterialAnimation
.
animationDisabled
({
SideNavigationViewController
.
backdropLayer
.
frame
=
self
.
view
.
bounds
SideNavigationViewController
.
backdropLayer
.
zPosition
=
900
SideNavigationViewController
.
backdropLayer
.
hidden
=
true
})
view
.
layer
.
addSublayer
(
SideNavigationViewController
.
backdropLayer
)
}
//
...
...
@@ -429,7 +435,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
//
private
func
prepareLeftGestures
()
{
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
viewContainer
=
MaterialView
(
frame
:
CGRectMake
(
originX
,
originY
,
width
,
height
))
viewContainer
!.
backgroundColor
=
MaterialColor
.
red
.
base
viewContainer
!.
autoresizingMask
=
[
.
FlexibleHeight
,
.
FlexibleWidth
]
viewContainer
!.
zPosition
=
1000
view
.
addSubview
(
viewContainer
!
)
}
//
// :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
c
=
viewContainer
{
addChildViewController
(
vc
)
vc
.
view
.
frame
=
c
.
frame
c
.
addSubview
(
vc
.
view
)
vc
.
didMoveToParentViewController
(
self
)
}
addChildViewController
(
vc
)
vc
.
view
.
frame
=
view
.
frame
view
.
addSubview
(
vc
.
view
)
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