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
80768582
Commit
80768582
authored
Jan 25, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial pass to update SideNav with the addition of a right side view
parent
9d14b588
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
288 additions
and
87 deletions
+288
-87
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController.xcodeproj/project.pbxproj
+14
-4
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/AppDelegate.swift
+1
-1
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/LeftViewController.swift
+6
-6
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/MainViewController.swift
+1
-1
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/RightViewController.swift
+172
-0
Material.xcodeproj/xcshareddata/xcschemes/Material.xcscheme
+0
-0
Sources/SideNavigationViewController.swift
+94
-75
No files found.
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController.xcodeproj/project.pbxproj
View file @
80768582
...
...
@@ -11,7 +11,10 @@
9642FA1D1C1B50E700022BC6
/* MainViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9642FA1C1C1B50E700022BC6
/* MainViewController.swift */
;
};
9642FA221C1B50E700022BC6
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9642FA211C1B50E700022BC6
/* Assets.xcassets */
;
};
9642FA251C1B50E700022BC6
/* LaunchScreen.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9642FA231C1B50E700022BC6
/* LaunchScreen.storyboard */
;
};
9642FA331C1B909700022BC6
/* SideViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9642FA321C1B909700022BC6
/* SideViewController.swift */
;
};
9642FA331C1B909700022BC6
/* LeftViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9642FA321C1B909700022BC6
/* LeftViewController.swift */
;
};
967585351C5692A4001E4268
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967585341C5692A4001E4268
/* Material.framework */
;
};
967585361C5692A4001E4268
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967585341C5692A4001E4268
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
967585381C569AA9001E4268
/* RightViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967585371C569AA9001E4268
/* RightViewController.swift */
;
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -21,6 +24,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
967585361C5692A4001E4268
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -34,7 +38,9 @@
9642FA211C1B50E700022BC6
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
9642FA241C1B50E700022BC6
/* Base */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.storyboard
;
name
=
Base
;
path
=
Base.lproj/LaunchScreen.storyboard
;
sourceTree
=
"<group>"
;
};
9642FA261C1B50E700022BC6
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
9642FA321C1B909700022BC6
/* SideViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
SideViewController.swift
;
sourceTree
=
"<group>"
;
};
9642FA321C1B909700022BC6
/* LeftViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
LeftViewController.swift
;
sourceTree
=
"<group>"
;
};
967585341C5692A4001E4268
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
967585371C569AA9001E4268
/* RightViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
RightViewController.swift
;
sourceTree
=
"<group>"
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -42,6 +48,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
967585351C5692A4001E4268
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -51,6 +58,7 @@
9642FA0E1C1B50E700022BC6
=
{
isa
=
PBXGroup
;
children
=
(
967585341C5692A4001E4268
/* Material.framework */
,
9642FA191C1B50E700022BC6
/* SideNavigationViewController */
,
9642FA181C1B50E700022BC6
/* Products */
,
);
...
...
@@ -69,10 +77,11 @@
children
=
(
9642FA1A1C1B50E700022BC6
/* AppDelegate.swift */
,
9642FA1C1C1B50E700022BC6
/* MainViewController.swift */
,
9642FA321C1B909700022BC6
/*
Side
ViewController.swift */
,
9642FA321C1B909700022BC6
/*
Left
ViewController.swift */
,
9642FA211C1B50E700022BC6
/* Assets.xcassets */
,
9642FA231C1B50E700022BC6
/* LaunchScreen.storyboard */
,
9642FA261C1B50E700022BC6
/* Info.plist */
,
967585371C569AA9001E4268
/* RightViewController.swift */
,
);
path
=
SideNavigationViewController
;
sourceTree
=
"<group>"
;
...
...
@@ -149,7 +158,8 @@
buildActionMask
=
2147483647
;
files
=
(
9642FA1D1C1B50E700022BC6
/* MainViewController.swift in Sources */
,
9642FA331C1B909700022BC6
/* SideViewController.swift in Sources */
,
967585381C569AA9001E4268
/* RightViewController.swift in Sources */
,
9642FA331C1B909700022BC6
/* LeftViewController.swift in Sources */
,
9642FA1B1C1B50E700022BC6
/* AppDelegate.swift in Sources */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
...
...
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/AppDelegate.swift
View file @
80768582
...
...
@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func
application
(
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
NSObject
:
AnyObject
]?)
->
Bool
{
// Override point for customization after application launch.
window
=
UIWindow
(
frame
:
UIScreen
.
mainScreen
()
.
bounds
)
window
!.
rootViewController
=
SideNavigationViewController
(
mainViewController
:
MainViewController
(),
sideViewController
:
Side
ViewController
())
window
!.
rootViewController
=
SideNavigationViewController
(
mainViewController
:
MainViewController
(),
leftViewController
:
Left
ViewController
())
window
!.
makeKeyAndVisible
()
return
true
}
...
...
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/
Side
ViewController.swift
→
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/
Left
ViewController.swift
View file @
80768582
...
...
@@ -29,7 +29,7 @@
*/
/*
The following is an example of setting a UITableView as the
Side
ViewController
The following is an example of setting a UITableView as the
Left
ViewController
within a SideNavigationViewController.
*/
...
...
@@ -42,7 +42,7 @@ private struct Item {
var
selected
:
Bool
}
class
Side
ViewController
:
UIViewController
{
class
Left
ViewController
:
UIViewController
{
/// A tableView used to display navigation items.
private
let
tableView
:
UITableView
=
UITableView
()
...
...
@@ -64,8 +64,8 @@ class SideViewController: UIViewController {
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
sideNavigationViewController
?
.
backdropColor
=
nil
sideNavigationViewController
?
.
depth
=
.
None
//
sideNavigationViewController?.backdropColor = nil
//
sideNavigationViewController?.depth = .None
}
...
...
@@ -137,7 +137,7 @@ class SideViewController: UIViewController {
}
/// TableViewDataSource methods.
extension
Side
ViewController
:
UITableViewDataSource
{
extension
Left
ViewController
:
UITableViewDataSource
{
/// Determines the number of rows in the tableView.
func
tableView
(
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
items
.
count
;
...
...
@@ -164,7 +164,7 @@ extension SideViewController: UITableViewDataSource {
}
/// UITableViewDelegate methods.
extension
Side
ViewController
:
UITableViewDelegate
{
extension
Left
ViewController
:
UITableViewDelegate
{
/// Sets the tableView cell height.
func
tableView
(
tableView
:
UITableView
,
heightForRowAtIndexPath
indexPath
:
NSIndexPath
)
->
CGFloat
{
return
64
...
...
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/MainViewController.swift
View file @
80768582
...
...
@@ -69,7 +69,7 @@ class MainViewController: UIViewController {
because any earlier may cause a race condition when instantiating
the MainViewController and SideViewController.
*/
sideNavigationViewController
?
.
set
Side
ViewWidth
(
view
.
bounds
.
width
-
88
,
hidden
:
true
,
animated
:
false
)
sideNavigationViewController
?
.
set
Left
ViewWidth
(
view
.
bounds
.
width
-
88
,
hidden
:
true
,
animated
:
false
)
}
/**
...
...
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/RightViewController.swift
0 → 100644
View file @
80768582
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
The following is an example of setting a UITableView as the RightViewController
within a SideNavigationViewController.
*/
import
UIKit
import
Material
private
struct
Item
{
var
text
:
String
var
imageName
:
String
var
selected
:
Bool
}
class
RightViewController
:
UIViewController
{
/// A tableView used to display navigation items.
private
let
tableView
:
UITableView
=
UITableView
()
/// A list of all the navigation items.
private
var
items
:
Array
<
Item
>
=
Array
<
Item
>
()
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
prepareItems
()
prepareProfileView
()
prepareTableView
()
}
/// General preparation statements.
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
clear
}
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
// sideNavigationViewController?.backdropColor = nil
// sideNavigationViewController?.depth = .None
}
/// Prepares the items that are displayed within the tableView.
private
func
prepareItems
()
{
items
.
append
(
Item
(
text
:
"Inbox"
,
imageName
:
"ic_inbox"
,
selected
:
true
))
items
.
append
(
Item
(
text
:
"Today"
,
imageName
:
"ic_today"
,
selected
:
false
))
items
.
append
(
Item
(
text
:
"Bookmarks"
,
imageName
:
"ic_book"
,
selected
:
false
))
items
.
append
(
Item
(
text
:
"Work"
,
imageName
:
"ic_work"
,
selected
:
false
))
items
.
append
(
Item
(
text
:
"Contacts"
,
imageName
:
"ic_contacts"
,
selected
:
false
))
items
.
append
(
Item
(
text
:
"Settings"
,
imageName
:
"ic_settings"
,
selected
:
false
))
}
/// Prepares profile view.
private
func
prepareProfileView
()
{
let
backgroundView
:
MaterialView
=
MaterialView
()
backgroundView
.
image
=
UIImage
(
named
:
"ProfileSideNavBackground"
)
let
profileView
:
MaterialView
=
MaterialView
()
profileView
.
image
=
UIImage
(
named
:
"Profile9"
)?
.
resize
(
toWidth
:
72
)
profileView
.
shape
=
.
Circle
profileView
.
borderColor
=
MaterialColor
.
white
profileView
.
borderWidth
=
.
Border3
let
nameLabel
:
UILabel
=
UILabel
()
nameLabel
.
text
=
"Michael Smith"
nameLabel
.
textColor
=
MaterialColor
.
white
nameLabel
.
font
=
RobotoFont
.
mediumWithSize
(
18
)
view
.
addSubview
(
backgroundView
)
backgroundView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromTop
(
view
,
child
:
backgroundView
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
backgroundView
)
MaterialLayout
.
height
(
view
,
child
:
backgroundView
,
height
:
170
)
backgroundView
.
addSubview
(
profileView
)
profileView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromTopLeft
(
backgroundView
,
child
:
profileView
,
top
:
20
,
left
:
20
)
MaterialLayout
.
size
(
backgroundView
,
child
:
profileView
,
width
:
72
,
height
:
72
)
backgroundView
.
addSubview
(
nameLabel
)
nameLabel
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottom
(
backgroundView
,
child
:
nameLabel
,
bottom
:
20
)
MaterialLayout
.
alignToParentHorizontally
(
backgroundView
,
child
:
nameLabel
,
left
:
20
,
right
:
20
)
}
/// Prepares the tableView.
private
func
prepareTableView
()
{
tableView
.
registerClass
(
UITableViewCell
.
self
,
forCellReuseIdentifier
:
"Cell"
)
tableView
.
dataSource
=
self
tableView
.
delegate
=
self
tableView
.
separatorStyle
=
.
None
// if !UIAccessibilityIsReduceTransparencyEnabled() {
// tableView.backgroundColor = MaterialColor.clear
// let blurEffect = UIBlurEffect(style: .Light)
// let blurEffectView = UIVisualEffectView(effect: blurEffect)
// tableView.backgroundView = blurEffectView
//
// //if you want translucent vibrant table view separator lines
// tableView.separatorEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
// }
// Use MaterialLayout to easily align the tableView.
view
.
addSubview
(
tableView
)
tableView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
tableView
,
top
:
170
)
}
}
/// TableViewDataSource methods.
extension
RightViewController
:
UITableViewDataSource
{
/// Determines the number of rows in the tableView.
func
tableView
(
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
items
.
count
;
}
/// Prepares the cells within the tableView.
func
tableView
(
tableView
:
UITableView
,
cellForRowAtIndexPath
indexPath
:
NSIndexPath
)
->
UITableViewCell
{
let
cell
:
UITableViewCell
=
tableView
.
dequeueReusableCellWithIdentifier
(
"Cell"
,
forIndexPath
:
indexPath
)
as
UITableViewCell
cell
.
backgroundColor
=
MaterialColor
.
clear
let
item
:
Item
=
items
[
indexPath
.
row
]
cell
.
selectionStyle
=
.
None
cell
.
textLabel
!.
text
=
item
.
text
cell
.
textLabel
!.
font
=
RobotoFont
.
medium
cell
.
imageView
!.
image
=
UIImage
(
named
:
item
.
imageName
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
cell
.
imageView
!.
tintColor
=
MaterialColor
.
cyan
.
darken4
if
item
.
selected
{
cell
.
textLabel
!.
textColor
=
MaterialColor
.
cyan
.
base
}
return
cell
}
}
/// UITableViewDelegate methods.
extension
RightViewController
:
UITableViewDelegate
{
/// Sets the tableView cell height.
func
tableView
(
tableView
:
UITableView
,
heightForRowAtIndexPath
indexPath
:
NSIndexPath
)
->
CGFloat
{
return
64
}
}
Material.xcodeproj/xcshareddata/xcschemes/Material
Kit
.xcscheme
→
Material.xcodeproj/xcshareddata/xcschemes/Material.xcscheme
View file @
80768582
File moved
Sources/SideNavigationViewController.swift
View file @
80768582
...
...
@@ -103,7 +103,7 @@ public protocol SideNavigationViewControllerDelegate {
public
class
SideNavigationViewController
:
UIViewController
,
UIGestureRecognizerDelegate
{
/**
A CGPoint property that is used internally to track
the original position of the
side
View when panning began.
the original position of the
left
View when panning began.
*/
private
var
originalPosition
:
CGPoint
=
CGPointZero
...
...
@@ -131,9 +131,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
A CGFloat property that accesses the horizontal threshold of
the SideNavigationViewController. When the panning gesture has
ended, if the position is beyond the horizontal threshold,
the
side
View is opened, if it is below the threshold, the
side
View is closed. The horizontal threshold is always at half
the width of the
side
View.
the
left
View is opened, if it is below the threshold, the
left
View is closed. The horizontal threshold is always at half
the width of the
left
View.
*/
public
private(set)
var
horizontalThreshold
:
CGFloat
=
0
...
...
@@ -158,12 +158,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
A CGFloat property that sets the animation duration of the
side
View when closing and opening. Defaults to 0.25.
left
View when closing and opening. Defaults to 0.25.
*/
public
var
animationDuration
:
CGFloat
=
0.25
/**
A Boolean property that enables and disables the
side
View from
A Boolean property that enables and disables the
left
View from
opening and closing. Defaults to true.
*/
public
var
enabled
:
Bool
=
true
{
...
...
@@ -179,22 +179,22 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
A Boolean property that triggers the status bar to be hidden
when the
side
View is opened. Defaults to true.
when the
left
View is opened. Defaults to true.
*/
public
var
hideStatusBar
:
Bool
=
true
/**
A MaterialDepth property that is used to set the depth of the
side
View when opened.
left
View when opened.
*/
public
var
depth
:
MaterialDepth
=
.
Depth2
/**
A MaterialView property that is used to hide and reveal the
sideViewController. It is very rare that this property will
leftViewController. It is very rare that this property will
need to be accessed externally.
*/
public
private(set)
var
side
View
:
MaterialView
!
public
private(set)
var
left
View
:
MaterialView
!
/// A CGFloat property to set the backdropLayer color opacity.
public
var
backdropOpacity
:
CGFloat
=
0.5
{
...
...
@@ -211,11 +211,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
A Boolean property that indicates whether the
side
View
A Boolean property that indicates whether the
left
View
is opened.
*/
public
var
opened
:
Bool
{
return
sideView
.
x
!=
-
side
ViewWidth
return
leftView
.
x
!=
-
left
ViewWidth
}
/**
...
...
@@ -228,25 +228,33 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
A UIViewController property that references the
active
side
UIViewController.
active
left
UIViewController.
*/
public
private(set)
var
sideViewController
:
UIViewController
!
public
private(set)
var
leftViewController
:
UIViewController
?
/**
A CGFloat property to access the width the sideView
A UIViewController property that references the
active right UIViewController.
*/
public
private(set)
var
rightViewController
:
UIViewController
?
/**
A CGFloat property to access the width the leftView
opens up to.
*/
public
private(set)
var
side
ViewWidth
:
CGFloat
=
240
public
private(set)
var
left
ViewWidth
:
CGFloat
=
240
/**
An initializer for the SideNavigationViewController.
- Parameter mainViewController: The main UIViewController.
- Parameter sideViewController: The side UIViewController.
- Parameter leftViewController: The left UIViewController.
- Parameter rightViewController: The right UIViewController.
*/
public
convenience
init
(
mainViewController
:
UIViewController
,
sideViewController
:
UIViewController
)
{
public
convenience
init
(
mainViewController
:
UIViewController
,
leftViewController
:
UIViewController
?
=
nil
,
rightViewController
:
UIViewController
?
=
nil
)
{
self
.
init
()
self
.
mainViewController
=
mainViewController
self
.
sideViewController
=
sideViewController
self
.
leftViewController
=
leftViewController
self
.
rightViewController
=
rightViewController
prepareView
()
}
...
...
@@ -254,13 +262,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
super
.
viewWillLayoutSubviews
()
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
backdropLayer
.
frame
=
self
.
view
.
bounds
self
.
sideView
.
width
=
self
.
side
ViewWidth
self
.
side
View
.
height
=
self
.
view
.
bounds
.
height
self
.
leftView
.
width
=
self
.
left
ViewWidth
self
.
left
View
.
height
=
self
.
view
.
bounds
.
height
}
horizontalThreshold
=
side
ViewWidth
/
2
sideViewController
.
view
.
frame
.
size
.
width
=
side
View
.
width
sideViewController
.
view
.
frame
.
size
.
height
=
side
View
.
height
sideViewController
.
view
.
center
=
CGPointMake
(
sideView
.
width
/
2
,
side
View
.
height
/
2
)
horizontalThreshold
=
left
ViewWidth
/
2
leftViewController
?
.
view
.
frame
.
size
.
width
=
left
View
.
width
leftViewController
?
.
view
.
frame
.
size
.
height
=
left
View
.
height
leftViewController
?
.
view
.
center
=
CGPointMake
(
leftView
.
width
/
2
,
left
View
.
height
/
2
)
}
/**
...
...
@@ -298,50 +306,50 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
A method that is used to set the width of the
side
View when
opened. This is the recommended method of setting the
side
View
A method that is used to set the width of the
left
View when
opened. This is the recommended method of setting the
left
View
width.
- Parameter width: A CGFloat value to set as the new width.
- Parameter hidden: A Boolean value of whether the
side
View
- Parameter hidden: A Boolean value of whether the
left
View
should be hidden after the width has been updated or not.
- Parameter animated: A Boolean value that indicates to animate
the
side
View width change.
the
left
View width change.
*/
public
func
set
Side
ViewWidth
(
width
:
CGFloat
,
hidden
:
Bool
,
animated
:
Bool
)
{
public
func
set
Left
ViewWidth
(
width
:
CGFloat
,
hidden
:
Bool
,
animated
:
Bool
)
{
let
w
:
CGFloat
=
(
hidden
?
-
width
:
width
)
/
2
side
ViewWidth
=
width
left
ViewWidth
=
width
if
animated
{
MaterialAnimation
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
self
.
side
View
.
width
=
width
self
.
side
View
.
position
.
x
=
w
self
.
left
View
.
width
=
width
self
.
left
View
.
position
.
x
=
w
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
false
}
}
else
{
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
side
View
.
width
=
width
self
.
side
View
.
position
.
x
=
w
self
.
left
View
.
width
=
width
self
.
left
View
.
position
.
x
=
w
}
}
}
/**
A method that toggles the
side
View opened if previously closed,
A method that toggles the
left
View opened if previously closed,
or closed if previously opened.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
side
View. Defaults to 0.
left
View. Defaults to 0.
*/
public
func
toggle
(
velocity
:
CGFloat
=
0
)
{
opened
?
close
(
velocity
)
:
open
(
velocity
)
}
/**
A method that opens the
side
View.
A method that opens the
left
View.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
side
View. Defaults to 0.
left
View. Defaults to 0.
*/
public
func
open
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
true
)
...
...
@@ -349,9 +357,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate
?
.
sideNavigationViewWillOpen
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
side
View
.
x
/
velocity
)))),
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
left
View
.
x
/
velocity
)))),
animations
:
{
[
unowned
self
]
in
self
.
sideView
.
position
=
CGPointMake
(
self
.
sideView
.
width
/
2
,
self
.
side
View
.
height
/
2
)
self
.
leftView
.
position
=
CGPointMake
(
self
.
leftView
.
width
/
2
,
self
.
left
View
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
false
self
.
showSideViewDepth
()
...
...
@@ -360,10 +368,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
A method that closes the
side
View.
A method that closes the
left
View.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
side
View. Defaults to 0.
left
View. Defaults to 0.
*/
public
func
close
(
velocity
:
CGFloat
=
0
)
{
toggleStatusBar
(
false
)
...
...
@@ -371,9 +379,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate
?
.
sideNavigationViewWillClose
?(
self
)
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
side
View
.
x
/
velocity
)))),
MaterialAnimation
.
animateWithDuration
(
Double
(
0
==
velocity
?
animationDuration
:
fmax
(
0.1
,
fmin
(
1
,
Double
(
left
View
.
x
/
velocity
)))),
animations
:
{
[
unowned
self
]
in
self
.
sideView
.
position
=
CGPointMake
(
-
self
.
sideView
.
width
/
2
,
self
.
side
View
.
height
/
2
)
self
.
leftView
.
position
=
CGPointMake
(
-
self
.
leftView
.
width
/
2
,
self
.
left
View
.
height
/
2
)
})
{
[
unowned
self
]
in
self
.
userInteractionEnabled
=
true
self
.
hideSideViewDepth
()
...
...
@@ -389,7 +397,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if
opened
&&
gestureRecognizer
==
sideTapGesture
{
let
point
:
CGPoint
=
touch
.
locationInView
(
view
)
delegate
?
.
sideNavigationViewDidTap
?(
self
,
point
:
point
)
return
!
isPointContainedWithinViewController
(
side
View
,
point
:
point
)
return
!
isPointContainedWithinViewController
(
left
View
,
point
:
point
)
}
}
return
false
...
...
@@ -405,25 +413,25 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
switch
recognizer
.
state
{
case
.
Began
:
backdropLayer
.
hidden
=
false
originalPosition
=
side
View
.
position
originalPosition
=
left
View
.
position
toggleStatusBar
(
true
)
showSideViewDepth
()
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
side
View
.
position
)
delegate
?
.
sideNavigationViewPanDidBegin
?(
self
,
point
:
left
View
.
position
)
case
.
Changed
:
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
side
View
)
let
w
:
CGFloat
=
side
View
.
width
let
translation
:
CGPoint
=
recognizer
.
translationInView
(
left
View
)
let
w
:
CGFloat
=
left
View
.
width
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
side
View
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
self
.
side
View
.
position
)
self
.
left
View
.
position
.
x
=
self
.
originalPosition
.
x
+
translation
.
x
>
(
w
/
2
)
?
(
w
/
2
)
:
self
.
originalPosition
.
x
+
translation
.
x
self
.
delegate
?
.
sideNavigationViewPanDidChange
?(
self
,
point
:
self
.
left
View
.
position
)
}
case
.
Ended
,
.
Cancelled
,
.
Failed
:
let
point
:
CGPoint
=
recognizer
.
velocityInView
(
recognizer
.
view
)
let
x
:
CGFloat
=
point
.
x
>=
1000
||
point
.
x
<=
-
1000
?
point
.
x
:
0
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
side
View
.
position
)
delegate
?
.
sideNavigationViewPanDidEnd
?(
self
,
point
:
left
View
.
position
)
if
sideView
.
x
<=
CGFloat
(
floor
(
-
side
ViewWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
if
leftView
.
x
<=
CGFloat
(
floor
(
-
left
ViewWidth
))
+
horizontalThreshold
||
point
.
x
<=
-
1000
{
close
(
x
)
}
else
{
open
(
x
)
...
...
@@ -462,28 +470,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
A method that prepares the
side
ViewController.
A method that prepares the
left
ViewController.
*/
private
func
prepare
Side
ViewController
()
{
sideViewController
.
view
.
clipsToBounds
=
true
prepareViewControllerWithinContainer
(
sideViewController
,
container
:
side
View
)
private
func
prepare
Left
ViewController
()
{
leftViewController
?
.
view
.
clipsToBounds
=
true
prepareViewControllerWithinContainer
(
leftViewController
,
container
:
left
View
)
}
/**
A method that prepares the sideView.
A method that prepares the rightViewController.
*/
private
func
prepareRightViewController
()
{
rightViewController
?
.
view
.
clipsToBounds
=
true
prepareViewControllerWithinContainer
(
rightViewController
,
container
:
leftView
)
}
/**
A method that prepares the leftView.
*/
private
func
prepareSideView
()
{
side
View
=
MaterialView
()
sideView
.
frame
=
CGRectMake
(
0
,
0
,
side
ViewWidth
,
view
.
frame
.
height
)
side
View
.
backgroundColor
=
MaterialColor
.
clear
view
.
addSubview
(
side
View
)
left
View
=
MaterialView
()
leftView
.
frame
=
CGRectMake
(
0
,
0
,
left
ViewWidth
,
view
.
frame
.
height
)
left
View
.
backgroundColor
=
MaterialColor
.
clear
view
.
addSubview
(
left
View
)
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
sideView
.
position
.
x
=
-
self
.
side
ViewWidth
/
2
self
.
side
View
.
zPosition
=
1000
self
.
leftView
.
position
.
x
=
-
self
.
left
ViewWidth
/
2
self
.
left
View
.
zPosition
=
1000
}
prepare
Side
ViewController
()
prepare
Left
ViewController
()
removeGestures
(
&
sidePanGesture
,
tap
:
&
sideTapGesture
)
prepareGestures
(
&
sidePanGesture
,
panSelector
:
"handlePanGesture:"
,
tap
:
&
sideTapGesture
,
tapSelector
:
"handleTapGesture:"
)
}
...
...
@@ -502,14 +518,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
A method that adds the passed in controller as a child of
the SideNavigationViewController within the passed in
container view.
- Parameter
c
ontroller: A UIViewController to add as a child.
- Parameter
viewC
ontroller: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private
func
prepareViewControllerWithinContainer
(
controller
:
UIViewController
,
container
:
UIView
)
{
addChildViewController
(
controller
)
container
.
addSubview
(
controller
.
view
)
controller
.
didMoveToParentViewController
(
self
)
private
func
prepareViewControllerWithinContainer
(
viewController
:
UIViewController
?,
container
:
UIView
)
{
if
let
v
:
UIViewController
=
viewController
{
addChildViewController
(
v
)
container
.
addSubview
(
v
.
view
)
v
.
didMoveToParentViewController
(
self
)
}
}
/**
...
...
@@ -597,21 +615,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
}
/**
A method that adds the depth to the
side
View depth property.
A method that adds the depth to the
left
View depth property.
*/
private
func
showSideViewDepth
()
{
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
side
View
.
depth
=
self
.
depth
self
.
left
View
.
depth
=
self
.
depth
}
}
/**
A method that removes the depth from the
side
View depth
A method that removes the depth from the
left
View depth
property.
*/
private
func
hideSideViewDepth
()
{
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
side
View
.
depth
=
.
None
self
.
left
View
.
depth
=
.
None
}
}
}
\ 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