Commit 801cfe50 by Daniel Dahan

updated SideNavigationViewController example

parent a8137ed7
......@@ -35,7 +35,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
......
......@@ -8,13 +8,10 @@
/* Begin PBXBuildFile section */
9642FA1B1C1B50E700022BC6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */; };
9642FA1D1C1B50E700022BC6 /* AMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1C1C1B50E700022BC6 /* AMainViewController.swift */; };
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 */; };
9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA301C1B906600022BC6 /* BMainViewController.swift */; };
9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* SideViewController.swift */; };
96607E031C441F54008D47D8 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96607E021C441F54008D47D8 /* MaterialKit.framework */; };
96607E041C441F54008D47D8 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96607E021C441F54008D47D8 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -24,7 +21,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96607E041C441F54008D47D8 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -34,13 +30,11 @@
/* Begin PBXFileReference section */
9642FA171C1B50E700022BC6 /* SideNavigationViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SideNavigationViewController.app; sourceTree = BUILT_PRODUCTS_DIR; };
9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9642FA1C1C1B50E700022BC6 /* AMainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AMainViewController.swift; sourceTree = "<group>"; };
9642FA1C1C1B50E700022BC6 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
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>"; };
9642FA301C1B906600022BC6 /* BMainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMainViewController.swift; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* SideViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideViewController.swift; sourceTree = "<group>"; };
96607E021C441F54008D47D8 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -48,7 +42,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96607E031C441F54008D47D8 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -58,7 +51,6 @@
9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup;
children = (
96607E021C441F54008D47D8 /* MaterialKit.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */,
);
......@@ -76,8 +68,7 @@
isa = PBXGroup;
children = (
9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */,
9642FA1C1C1B50E700022BC6 /* AMainViewController.swift */,
9642FA301C1B906600022BC6 /* BMainViewController.swift */,
9642FA1C1C1B50E700022BC6 /* MainViewController.swift */,
9642FA321C1B909700022BC6 /* SideViewController.swift */,
9642FA211C1B50E700022BC6 /* Assets.xcassets */,
9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */,
......@@ -157,10 +148,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9642FA1D1C1B50E700022BC6 /* AMainViewController.swift in Sources */,
9642FA1D1C1B50E700022BC6 /* MainViewController.swift in Sources */,
9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */,
9642FA1B1C1B50E700022BC6 /* AppDelegate.swift in Sources */,
9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -36,11 +36,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
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: AMainViewController(), sideViewController: SideViewController())
window!.rootViewController = SideNavigationViewController(mainViewController: MainViewController(), sideViewController: SideViewController())
window!.makeKeyAndVisible()
return true
}
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ProfileSideNavBackground.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_contacts.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_contacts_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_contacts_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_inbox.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_inbox_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_inbox_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_today.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_today_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_today_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_work.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_work_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_work_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
/*
* 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 MaterialKit 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.
*/
import UIKit
import MaterialKit
class BMainViewController: UIViewController {
lazy var enabledButton: RaisedButton = RaisedButton()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareFabButton()
}
internal func handleSwapViewControllers() {
sideNavigationViewController?.open()
}
internal func handleEnabledButton() {
if true == sideNavigationViewController?.enabled {
sideNavigationViewController?.enabled = false
enabledButton.setTitle("Disabled", forState: .Normal)
} else {
sideNavigationViewController?.enabled = true
enabledButton.setTitle("Enabled", forState: .Normal)
}
}
private func prepareView() {
view.backgroundColor = MaterialColor.blue.base
prepareEnabledButton()
}
private func prepareEnabledButton() {
enabledButton.setTitle(true == sideNavigationViewController?.enabled ? "Enabled" : "Disabled", forState: .Normal)
enabledButton.addTarget(self, action: "handleEnabledButton", forControlEvents: .TouchUpInside)
// Add the enabledButton through MaterialLayout.
view.addSubview(enabledButton)
enabledButton.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopRight(view, child: enabledButton, top: 124, right: 24)
MaterialLayout.size(view, child: enabledButton, width: 200, height: 50)
}
private func prepareFabButton() {
let button: FabButton = FabButton()
button.addTarget(self, action: "handleSwapViewControllers", forControlEvents: .TouchUpInside)
// Add the button through MaterialLayout.
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottomRight(view, child: button, bottom: 24, right: 24)
MaterialLayout.size(view, child: button, width: 64, height: 64)
}
}
......@@ -29,7 +29,10 @@
*/
/*
The following is an example of setting a UITableView as the MainViewController
within a SideNavigationViewController. There is a NavigationBarView that is
used for navigation, with a menu button that opens the
SideNavigationViewController.
*/
import UIKit
......@@ -41,7 +44,7 @@ private struct Item {
var image: UIImage?
}
class AMainViewController: UIViewController {
class MainViewController: UIViewController {
/// A tableView used to display Bond entries.
private let tableView: UITableView = UITableView()
......@@ -57,6 +60,18 @@ class AMainViewController: UIViewController {
prepareMaterialKitButton()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
/*
Set the width of the SideNavigationViewController. Be mindful
of when setting this value. It is set in the viewWillAppear method,
because any earlier may cause a race condition when instantiating
the MainViewController and SideViewController.
*/
sideNavigationViewController?.setSideViewWidth(view.bounds.width - 88, hidden: true, animated: false)
}
/**
Handles the menu button click, which opens the
SideNavigationViewController.
......@@ -172,7 +187,7 @@ class AMainViewController: UIViewController {
}
/// TableViewDataSource methods.
extension AMainViewController: UITableViewDataSource {
extension MainViewController: UITableViewDataSource {
/// Determines the number of rows in the tableView.
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count;
......@@ -190,12 +205,10 @@ extension AMainViewController: UITableViewDataSource {
let item: Item = items[indexPath.row]
cell.selectionStyle = .None
cell.textLabel!.text = item.text
cell.detailTextLabel!.text = item.detail
cell.detailTextLabel!.textColor = MaterialColor.grey.darken4
cell.imageView!.image = item.image?.resize(toWidth: 36)
cell.imageView!.layer.cornerRadius = 18
return cell
}
......@@ -217,7 +230,7 @@ extension AMainViewController: UITableViewDataSource {
}
/// UITableViewDelegate methods.
extension AMainViewController: UITableViewDelegate {
extension MainViewController: UITableViewDelegate {
/// Sets the tableView cell height.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
......
......@@ -28,6 +28,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
The following is an example of setting a UITableView as the SideViewController
within a SideNavigationViewController.
*/
import UIKit
import MaterialKit
......@@ -47,19 +52,37 @@ class SideViewController: UIViewController {
super.viewDidLoad()
prepareView()
prepareItems()
prepareProfileView()
prepareTableView()
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.purple.base
view.backgroundColor = MaterialColor.white
}
/// Prepares the items that are displayed within the tableView.
private func prepareItems() {
items.append(Item(text: "Inbox", image: UIImage(named: "ic_inbox")))
items.append(Item(text: "Today", image: UIImage(named: "ic_today")))
items.append(Item(text: "Bookmarks", image: UIImage(named: "ic_book")))
items.append(Item(text: "Work", image: UIImage(named: "ic_work")))
items.append(Item(text: "Contacts", image: UIImage(named: "ic_contacts")))
items.append(Item(text: "Settings", image: UIImage(named: "ic_settings")))
}
/// Prepares profile view.
private func prepareProfileView() {
let backgroundView: MaterialView = MaterialView()
backgroundView.image = UIImage(named: "ProfileSideNavBackground")
view.addSubview(backgroundView)
backgroundView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: backgroundView)
MaterialLayout.alignToParentHorizontally(view, child: backgroundView)
MaterialLayout.height(view, child: backgroundView, height: 140)
}
/// Prepares the tableView.
private func prepareTableView() {
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
......@@ -96,16 +119,8 @@ extension SideViewController: UITableViewDataSource {
/// UITableViewDelegate methods.
extension SideViewController: UITableViewDelegate {
/// A delegation method that is executed when an item row is selected.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
sideNavigationViewController?.transitionFromMainViewController(sideNavigationViewController?.mainViewController is AMainViewController ? BMainViewController() : AMainViewController(),
duration: 0.25,
options: .TransitionCrossDissolve,
animations: nil,
completion: { (result: Bool) in
self.sideNavigationViewController?.close()
}
)
/// Sets the tableView cell height.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 64
}
}
Pod::Spec.new do |s|
s.name = 'MK'
s.version = '1.27.12'
s.version = '1.27.13'
s.license = 'BSD'
s.summary = 'Beautiful Material Design in Swift.'
s.homepage = 'http://materialkit.io'
......
......@@ -67,6 +67,7 @@ The MaterialKit framework is a fast growing project and will encounter changes t
### A Quick Tour
* [SideNavigationViewController](#sidenavigationviewcontroller)
* [TextField](#textfield)
* [TextView](#textview)
* [MaterialLayer](#materiallayer)
......@@ -76,7 +77,6 @@ The MaterialKit framework is a fast growing project and will encounter changes t
* [RaisedButton](#raisedbutton)
* [FabButton](#fabbutton)
* [NavigationBarView](#navigationbarview)
* [SideNavigationViewController](#sidenavigationviewcontroller)
* [CardView](#cardview)
* [ImageCardView](#imagecardview)
* [CaptureView](#captureview)
......@@ -96,6 +96,13 @@ The MaterialKit framework is a fast growing project and will encounter changes t
* TimePicker
* More Examples
<a name="sidenavigationviewcontroller"></a>
### SideNavigationViewController
The SideNavigationViewController is an app wide navigation pattern. It generally provides overall app navigation with other useful items. Below is an example of the SideNavigationViewController and in the Examples Programmatic directory, an example project is available using this component.
![MaterialKitSideNavigationViewController](http://www.materialkit.io/MK/MaterialKitSideNavigationViewController.gif)
<a name="textfield"></a>
### TextField
......@@ -312,13 +319,6 @@ MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
```
<a name="sidenavigationviewcontroller"></a>
### SideNavigationViewController
The SideNavigationViewController is an app wide navigation pattern. It generally provides overall app navigation with other useful items. Below is an example of the SideNavigationViewController and in the Examples Programmatic directory, an example project is available using this component.
![MaterialKitSideNavigationViewController](http://www.materialkit.io/MK/MaterialKitSideNavigationViewController.gif)
<a name="cardview"></a>
### CardView
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.27.12</string>
<string>1.27.13</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment