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
46ca088f
Commit
46ca088f
authored
Aug 27, 2015
by
adamdahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-16: logic updates to side nav + remove unnecessary calls to transition appearance methods
parent
4b82cec3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
78 deletions
+32
-78
Source/SideNavController.swift
+32
-78
No files found.
Source/SideNavController.swift
View file @
46ca088f
...
@@ -77,7 +77,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -77,7 +77,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
public
static
var
shadowOffset
:
CGSize
=
CGSizeZero
public
static
var
shadowOffset
:
CGSize
=
CGSizeZero
public
static
var
contentViewScale
:
CGFloat
=
1
public
static
var
contentViewScale
:
CGFloat
=
1
public
static
var
contentViewOpacity
:
CGFloat
=
0.4
public
static
var
contentViewOpacity
:
CGFloat
=
0.4
public
static
var
shouldH
ideStatusBar
:
Bool
=
true
public
static
var
h
ideStatusBar
:
Bool
=
true
public
static
var
pointOfNoReturnWidth
:
CGFloat
=
48
public
static
var
pointOfNoReturnWidth
:
CGFloat
=
48
public
static
var
pointOfNoReturnheight
:
CGFloat
=
48
public
static
var
pointOfNoReturnheight
:
CGFloat
=
48
public
static
var
backdropViewContainerBackgroundColor
:
UIColor
=
.
blackColor
()
public
static
var
backdropViewContainerBackgroundColor
:
UIColor
=
.
blackColor
()
...
@@ -88,8 +88,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -88,8 +88,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
public
static
var
rightBezelWidth
:
CGFloat
=
16
public
static
var
rightBezelWidth
:
CGFloat
=
16
public
static
var
rightViewContainerWidth
:
CGFloat
=
240
public
static
var
rightViewContainerWidth
:
CGFloat
=
240
public
static
var
rightPanFromBezel
:
Bool
=
true
public
static
var
rightPanFromBezel
:
Bool
=
true
public
static
var
bottomBezelHeight
:
CGFloat
=
16
public
static
var
bottomBezelHeight
:
CGFloat
=
48
public
static
var
bottomViewContainerHeight
:
CGFloat
=
2
7
0
public
static
var
bottomViewContainerHeight
:
CGFloat
=
2
4
0
public
static
var
bottomPanFromBezel
:
Bool
=
true
public
static
var
bottomPanFromBezel
:
Bool
=
true
}
}
...
@@ -109,7 +109,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -109,7 +109,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
:name: isLeftContainerOpened
:name: isLeftContainerOpened
*/
*/
public
var
isLeftContainerOpened
:
Bool
{
public
var
isLeftContainerOpened
:
Bool
{
return
0
==
leftViewContainer
?
.
frame
.
origin
.
x
if
let
c
=
leftViewContainer
{
return
c
.
frame
.
origin
.
x
!=
leftOriginX
}
return
false
}
}
/**
/**
...
@@ -117,7 +120,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -117,7 +120,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
*/
*/
public
var
isRightContainerOpened
:
Bool
{
public
var
isRightContainerOpened
:
Bool
{
if
let
c
=
rightViewContainer
{
if
let
c
=
rightViewContainer
{
return
c
.
frame
.
origin
.
x
==
rightOriginX
-
c
.
frame
.
size
.
width
return
c
.
frame
.
origin
.
x
!=
rightOriginX
}
}
return
false
return
false
}
}
...
@@ -127,7 +130,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -127,7 +130,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
*/
*/
public
var
isBottomContainerOpened
:
Bool
{
public
var
isBottomContainerOpened
:
Bool
{
if
let
c
=
bottomViewContainer
{
if
let
c
=
bottomViewContainer
{
return
c
.
frame
.
origin
.
y
==
bottomOriginY
-
c
.
frame
.
size
.
height
return
c
.
frame
.
origin
.
y
!=
bottomOriginY
}
}
return
false
return
false
}
}
...
@@ -298,8 +301,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -298,8 +301,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self
.
init
()
self
.
init
()
self
.
mainViewController
=
mainViewController
self
.
mainViewController
=
mainViewController
self
.
bottomViewController
=
bottomViewController
self
.
bottomViewController
=
bottomViewController
setup
View
()
prepare
View
()
setup
BottomView
()
prepare
BottomView
()
}
}
/**
/**
...
@@ -324,10 +327,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -324,10 +327,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self
.
leftViewController
=
leftViewController
self
.
leftViewController
=
leftViewController
self
.
bottomViewController
=
bottomViewController
self
.
bottomViewController
=
bottomViewController
self
.
rightViewController
=
rightViewController
self
.
rightViewController
=
rightViewController
setup
View
()
prepare
View
()
setup
LeftView
()
prepare
LeftView
()
setup
BottomView
()
prepare
BottomView
()
setup
RightView
()
prepare
RightView
()
}
}
/**
/**
...
@@ -338,9 +341,9 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -338,9 +341,9 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self
.
mainViewController
=
mainViewController
self
.
mainViewController
=
mainViewController
self
.
bottomViewController
=
bottomViewController
self
.
bottomViewController
=
bottomViewController
self
.
rightViewController
=
rightViewController
self
.
rightViewController
=
rightViewController
setup
View
()
prepare
View
()
setup
BottomView
()
prepare
BottomView
()
setup
RightView
()
prepare
RightView
()
}
}
//
//
...
@@ -362,44 +365,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -362,44 +365,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
prepareContainedViewController
(
&
bottomViewContainer
,
viewController
:
&
bottomViewController
)
prepareContainedViewController
(
&
bottomViewContainer
,
viewController
:
&
bottomViewController
)
}
}
//
// :name: viewWillTransitionToSize
//
public
override
func
viewWillTransitionToSize
(
size
:
CGSize
,
withTransitionCoordinator
coordinator
:
UIViewControllerTransitionCoordinator
)
{
super
.
viewWillTransitionToSize
(
size
,
withTransitionCoordinator
:
coordinator
)
mainViewContainer
?
.
transform
=
CGAffineTransformMakeScale
(
1
,
1
)
leftViewContainer
?
.
hidden
=
true
rightViewContainer
?
.
hidden
=
true
bottomViewContainer
?
.
hidden
=
true
coordinator
.
animateAlongsideTransition
(
nil
)
{
_
in
self
.
toggleWindow
()
self
.
backdropViewContainer
?
.
layer
.
opacity
=
0
self
.
mainViewContainer
?
.
transform
=
CGAffineTransformMakeScale
(
1
,
1
)
self
.
isUserInteractionEnabled
=
true
if
let
vc
=
self
.
leftViewContainer
{
vc
.
frame
.
origin
.
x
=
self
.
leftOriginX
vc
.
hidden
=
false
self
.
removeShadow
(
&
self
.
leftViewContainer
)
self
.
prepareLeftGestures
()
}
if
let
vc
=
self
.
rightViewContainer
{
vc
.
frame
.
origin
.
x
=
self
.
rightOriginX
vc
.
hidden
=
false
self
.
removeShadow
(
&
self
.
rightViewContainer
)
self
.
prepareRightGestures
()
}
if
let
vc
=
self
.
bottomViewContainer
{
vc
.
frame
.
origin
.
y
=
self
.
bottomOriginY
vc
.
hidden
=
false
self
.
removeShadow
(
&
self
.
bottomViewContainer
)
self
.
prepareBottomGestures
()
}
}
}
/**
/**
:name: toggleLeftViewContainer
:name: toggleLeftViewContainer
*/
*/
...
@@ -431,7 +396,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -431,7 +396,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
}
}
)
{
_
in
)
{
_
in
self
.
isUserInteractionEnabled
=
false
self
.
isUserInteractionEnabled
=
false
self
.
leftViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Opened
c
.
state
=
.
Opened
delegate
?
.
sideNavDidOpenLeftViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidOpenLeftViewContainer
?(
self
,
container
:
c
)
...
@@ -456,7 +420,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -456,7 +420,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
}
}
)
{
_
in
)
{
_
in
self
.
isUserInteractionEnabled
=
false
self
.
isUserInteractionEnabled
=
false
self
.
rightViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Opened
c
.
state
=
.
Opened
delegate
?
.
sideNavDidOpenRightViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidOpenRightViewContainer
?(
self
,
container
:
c
)
...
@@ -481,7 +444,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -481,7 +444,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
}
}
)
{
_
in
)
{
_
in
self
.
isUserInteractionEnabled
=
false
self
.
isUserInteractionEnabled
=
false
self
.
rightViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Opened
c
.
state
=
.
Opened
delegate
?
.
sideNavDidOpenRightViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidOpenRightViewContainer
?(
self
,
container
:
c
)
...
@@ -507,7 +469,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -507,7 +469,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
)
{
_
in
)
{
_
in
self
.
removeShadow
(
&
self
.
leftViewContainer
)
self
.
removeShadow
(
&
self
.
leftViewContainer
)
self
.
isUserInteractionEnabled
=
true
self
.
isUserInteractionEnabled
=
true
self
.
leftViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Closed
c
.
state
=
.
Closed
delegate
?
.
sideNavDidCloseLeftViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidCloseLeftViewContainer
?(
self
,
container
:
c
)
...
@@ -533,7 +494,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -533,7 +494,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
)
{
_
in
)
{
_
in
self
.
removeShadow
(
&
self
.
rightViewContainer
)
self
.
removeShadow
(
&
self
.
rightViewContainer
)
self
.
isUserInteractionEnabled
=
true
self
.
isUserInteractionEnabled
=
true
self
.
rightViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Closed
c
.
state
=
.
Closed
delegate
?
.
sideNavDidCloseRightViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidCloseRightViewContainer
?(
self
,
container
:
c
)
...
@@ -559,7 +519,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -559,7 +519,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
)
{
_
in
)
{
_
in
self
.
removeShadow
(
&
self
.
bottomViewContainer
)
self
.
removeShadow
(
&
self
.
bottomViewContainer
)
self
.
isUserInteractionEnabled
=
true
self
.
isUserInteractionEnabled
=
true
self
.
bottomViewController
?
.
endAppearanceTransition
()
}
}
c
.
state
=
.
Closed
c
.
state
=
.
Closed
delegate
?
.
sideNavDidCloseBottomViewContainer
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidCloseBottomViewContainer
?(
self
,
container
:
c
)
...
@@ -653,7 +612,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -653,7 +612,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
//
//
// :name: prepareLeftView
// :name: prepareLeftView
//
//
internal
func
setup
LeftView
()
{
internal
func
prepare
LeftView
()
{
prepareContainer
(
&
leftContainer
,
viewContainer
:
&
leftViewContainer
,
originX
:
leftOriginX
,
originY
:
0
,
width
:
options
.
leftViewContainerWidth
,
height
:
view
.
bounds
.
size
.
height
)
prepareContainer
(
&
leftContainer
,
viewContainer
:
&
leftViewContainer
,
originX
:
leftOriginX
,
originY
:
0
,
width
:
options
.
leftViewContainerWidth
,
height
:
view
.
bounds
.
size
.
height
)
prepareLeftGestures
()
prepareLeftGestures
()
}
}
...
@@ -661,15 +620,15 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -661,15 +620,15 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
//
//
// :name: prepareRightView
// :name: prepareRightView
//
//
internal
func
setup
RightView
()
{
internal
func
prepare
RightView
()
{
prepareContainer
(
&
rightContainer
,
viewContainer
:
&
rightViewContainer
,
originX
:
rightOriginX
,
originY
:
0
,
width
:
options
.
rightViewContainerWidth
,
height
:
view
.
bounds
.
size
.
height
)
prepareContainer
(
&
rightContainer
,
viewContainer
:
&
rightViewContainer
,
originX
:
rightOriginX
,
originY
:
0
,
width
:
options
.
rightViewContainerWidth
,
height
:
view
.
bounds
.
size
.
height
)
prepareRightGestures
()
prepareRightGestures
()
}
}
//
//
// :name:
setup
BottomView
// :name:
prepare
BottomView
//
//
internal
func
setup
BottomView
()
{
internal
func
prepare
BottomView
()
{
prepareContainer
(
&
bottomContainer
,
viewContainer
:
&
bottomViewContainer
,
originX
:
0
,
originY
:
bottomOriginY
,
width
:
view
.
bounds
.
size
.
width
,
height
:
options
.
bottomViewContainerHeight
)
prepareContainer
(
&
bottomContainer
,
viewContainer
:
&
bottomViewContainer
,
originX
:
0
,
originY
:
bottomOriginY
,
width
:
view
.
bounds
.
size
.
width
,
height
:
options
.
bottomViewContainerHeight
)
prepareBottomGestures
()
prepareBottomGestures
()
}
}
...
@@ -712,9 +671,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -712,9 +671,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
if
let
vc
=
leftViewContainer
{
if
let
vc
=
leftViewContainer
{
if
let
c
=
leftContainer
{
if
let
c
=
leftContainer
{
if
.
Began
==
gesture
.
state
{
if
.
Began
==
gesture
.
state
{
leftViewController
?
.
beginAppearanceTransition
(
!
isLeftContainerOpened
,
animated
:
true
)
addShadow
(
&
leftViewContainer
)
addShadow
(
&
leftViewContainer
)
toggle
Window
(
shouldOpen
:
true
)
toggle
StatusBar
(
hide
:
true
)
c
.
state
=
isLeftContainerOpened
?
.
Opened
:
.
Closed
c
.
state
=
isLeftContainerOpened
?
.
Opened
:
.
Closed
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
frame
=
vc
.
frame
c
.
frame
=
vc
.
frame
...
@@ -764,9 +722,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -764,9 +722,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
state
=
isRightContainerOpened
?
.
Opened
:
.
Closed
c
.
state
=
isRightContainerOpened
?
.
Opened
:
.
Closed
c
.
frame
=
vc
.
frame
c
.
frame
=
vc
.
frame
rightViewController
?
.
beginAppearanceTransition
(
!
isRightContainerOpened
,
animated
:
true
)
addShadow
(
&
rightViewContainer
)
addShadow
(
&
rightViewContainer
)
toggle
Window
(
shouldOpen
:
true
)
toggle
StatusBar
(
hide
:
true
)
delegate
?
.
sideNavDidBeginRightPan
?(
self
,
container
:
c
)
delegate
?
.
sideNavDidBeginRightPan
?(
self
,
container
:
c
)
}
else
if
.
Changed
==
gesture
.
state
{
}
else
if
.
Changed
==
gesture
.
state
{
c
.
point
=
gesture
.
translationInView
(
gesture
.
view
!
)
c
.
point
=
gesture
.
translationInView
(
gesture
.
view
!
)
...
@@ -811,9 +768,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -811,9 +768,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
if
.
Began
==
gesture
.
state
{
if
.
Began
==
gesture
.
state
{
if
let
vc
=
bottomViewContainer
{
if
let
vc
=
bottomViewContainer
{
if
let
c
=
bottomContainer
{
if
let
c
=
bottomContainer
{
bottomViewController
?
.
beginAppearanceTransition
(
!
isBottomContainerOpened
,
animated
:
true
)
addShadow
(
&
bottomViewContainer
)
addShadow
(
&
bottomViewContainer
)
toggle
Window
(
shouldOpen
:
true
)
toggle
StatusBar
(
hide
:
true
)
c
.
state
=
isBottomContainerOpened
?
.
Opened
:
.
Closed
c
.
state
=
isBottomContainerOpened
?
.
Opened
:
.
Closed
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
point
=
gesture
.
locationInView
(
view
)
c
.
frame
=
vc
.
frame
c
.
frame
=
vc
.
frame
...
@@ -885,16 +841,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -885,16 +841,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
}
}
//
//
// :name: toggle
Window
// :name: toggle
StatusBar
//
//
private
func
toggle
Window
(
shouldOpen
:
Bool
=
false
)
{
private
func
toggle
StatusBar
(
hide
:
Bool
=
false
)
{
if
options
.
shouldH
ideStatusBar
{
if
options
.
h
ideStatusBar
{
if
isViewBasedAppearance
{
if
isViewBasedAppearance
{
UIApplication
.
sharedApplication
()
.
setStatusBarHidden
(
shouldOpen
,
withAnimation
:
.
Slide
)
UIApplication
.
sharedApplication
()
.
setStatusBarHidden
(
hide
,
withAnimation
:
.
Slide
)
}
else
{
}
else
{
dispatch_async
(
dispatch_get_main_queue
(),
{
dispatch_async
(
dispatch_get_main_queue
(),
{
if
let
w
=
UIApplication
.
sharedApplication
()
.
keyWindow
{
if
let
w
=
UIApplication
.
sharedApplication
()
.
keyWindow
{
w
.
windowLevel
=
UIWindowLevelStatusBar
+
(
shouldOpen
?
1
:
0
)
w
.
windowLevel
=
hide
?
UIWindowLevelStatusBar
+
1
:
0
}
}
})
})
}
}
...
@@ -1041,17 +997,15 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
...
@@ -1041,17 +997,15 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
// :name: prepareContainerToOpen
// :name: prepareContainerToOpen
//
//
private
func
prepareContainerToOpen
(
inout
viewController
:
UIViewController
?,
inout
viewContainer
:
UIView
?,
state
:
SideNavState
)
{
private
func
prepareContainerToOpen
(
inout
viewController
:
UIViewController
?,
inout
viewContainer
:
UIView
?,
state
:
SideNavState
)
{
viewController
?
.
beginAppearanceTransition
(
.
Opened
==
state
,
animated
:
true
)
addShadow
(
&
viewContainer
)
addShadow
(
&
viewContainer
)
toggle
Window
(
shouldOpen
:
true
)
toggle
StatusBar
(
hide
:
true
)
}
}
//
//
// :name: prepareContainerToClose
// :name: prepareContainerToClose
//
//
private
func
prepareContainerToClose
(
inout
viewController
:
UIViewController
?,
state
:
SideNavState
)
{
private
func
prepareContainerToClose
(
inout
viewController
:
UIViewController
?,
state
:
SideNavState
)
{
viewController
?
.
beginAppearanceTransition
(
.
Opened
==
state
,
animated
:
true
)
toggleStatusBar
()
toggleWindow
()
}
}
//
//
...
...
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