Commit e9b3b3ff by Daniel Dahan

added AppBottomNavigationController to example App project, which organizes the…

added AppBottomNavigationController to example App project, which organizes the BottomNavigationController
parent 54ea0e75
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
960CDA461D09F84000387CE8 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 960CDA451D09F84000387CE8 /* Material.framework */; }; 960CDA491D09FF3E00387CE8 /* AppBottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 960CDA481D09FF3E00387CE8 /* AppBottomNavigationController.swift */; };
960CDA471D09F84000387CE8 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 960CDA451D09F84000387CE8 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */; }; 96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */; };
96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */; }; 96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */; };
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; }; 9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; };
...@@ -30,7 +29,6 @@ ...@@ -30,7 +29,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
960CDA471D09F84000387CE8 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -38,7 +36,7 @@ ...@@ -38,7 +36,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
960CDA451D09F84000387CE8 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-dciwtavdzrmtrifplxfnouazaqvx/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; }; 960CDA481D09FF3E00387CE8 /* AppBottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppBottomNavigationController.swift; sourceTree = "<group>"; };
96162C6B1CA71C8700E3A235 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; }; 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; }; 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
...@@ -60,7 +58,6 @@ ...@@ -60,7 +58,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
960CDA461D09F84000387CE8 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -70,7 +67,6 @@ ...@@ -70,7 +67,6 @@
9663F9251C7A744500AF0965 = { 9663F9251C7A744500AF0965 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
960CDA451D09F84000387CE8 /* Material.framework */,
9663F9301C7A744600AF0965 /* App */, 9663F9301C7A744600AF0965 /* App */,
9663F92F1C7A744600AF0965 /* Products */, 9663F92F1C7A744600AF0965 /* Products */,
); );
...@@ -89,14 +85,15 @@ ...@@ -89,14 +85,15 @@
children = ( children = (
9663F9311C7A744600AF0965 /* AppDelegate.swift */, 9663F9311C7A744600AF0965 /* AppDelegate.swift */,
9663F9471C7A749400AF0965 /* AppNavigationController.swift */, 9663F9471C7A749400AF0965 /* AppNavigationController.swift */,
960CDA481D09FF3E00387CE8 /* AppBottomNavigationController.swift */,
9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */, 9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */,
9663F94B1C7A74C700AF0965 /* AppMenuController.swift */, 9663F94B1C7A74C700AF0965 /* AppMenuController.swift */,
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */, 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */,
96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */, 96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */,
9663F9331C7A744600AF0965 /* RecommendationViewController.swift */,
9663F9511C7A751D00AF0965 /* ItemViewController.swift */, 9663F9511C7A751D00AF0965 /* ItemViewController.swift */,
96162C6B1CA71C8700E3A235 /* VideoViewController.swift */, 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */,
96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */, 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */,
9663F9331C7A744600AF0965 /* RecommendationViewController.swift */,
9663F9381C7A744600AF0965 /* Assets.xcassets */, 9663F9381C7A744600AF0965 /* Assets.xcassets */,
9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */, 9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */,
9663F93D1C7A744600AF0965 /* Info.plist */, 9663F93D1C7A744600AF0965 /* Info.plist */,
...@@ -185,6 +182,7 @@ ...@@ -185,6 +182,7 @@
96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */, 96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */,
9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */, 9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */,
96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */, 96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */,
960CDA491D09FF3E00387CE8 /* AppBottomNavigationController.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
/*
* 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 using a MenuController to control the
flow of your application.
*/
import UIKit
import Material
class AppBottomNavigationController: BottomNavigationController {
/// NavigationBar menu button.
private var menuButton: IconButton!
/// NavigationBar switch control.
private var switchControl: MaterialSwitch!
/// NavigationBar search button.
private var searchButton: IconButton!
override func prepareView() {
super.prepareView()
prepareMenuButton()
prepareSwitchControl()
prepareSearchButton()
prepareNavigationItem()
prepareViewControllers()
prepareTabBar()
}
/// Handles the menuButton.
internal func handleMenuButton() {
sideNavigationController?.openLeftView()
}
/// Handles the searchButton.
internal func handleSearchButton() {
let recommended: Array<MaterialDataSourceItem> = Array<MaterialDataSourceItem>()
let vc: AppSearchBarController = AppSearchBarController(rootViewController: RecommendationViewController(dataSourceItems: recommended))
vc.modalTransitionStyle = .CrossDissolve
presentViewController(vc, animated: true, completion: nil)
}
/// Prepares the menuButton.
private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.cm.menu
menuButton = IconButton()
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
}
/// Prepares the switchControl.
private func prepareSwitchControl() {
switchControl = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
}
/// Prepares the searchButton.
private func prepareSearchButton() {
let image: UIImage? = MaterialIcon.cm.search
searchButton = IconButton()
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
}
/// Prepares the navigationItem.
private func prepareNavigationItem() {
navigationItem.title = "Recipes"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, searchButton]
}
/// Prepares the view controllers.
private func prepareViewControllers() {
let menuController: AppMenuController = AppMenuController(rootViewController: RecipesViewController())
menuController.edgesForExtendedLayout = .None
viewControllers = [menuController, VideoViewController(), PhotoViewController()]
selectedIndex = 0
}
/// Prepares the tabBar.
private func prepareTabBar() {
tabBar.tintColor = MaterialColor.white
tabBar.backgroundColor = MaterialColor.grey.darken4
}
}
...@@ -38,14 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -38,14 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let menuController: AppMenuController = AppMenuController(rootViewController: RecipesViewController()) let bottomNavigationController: AppBottomNavigationController = AppBottomNavigationController()
menuController.edgesForExtendedLayout = .None
let bottomNavigationController: BottomNavigationController = BottomNavigationController()
bottomNavigationController.viewControllers = [menuController, VideoViewController(), PhotoViewController()]
bottomNavigationController.selectedIndex = 0
bottomNavigationController.tabBar.tintColor = MaterialColor.white
bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4
let navigationController: AppNavigationController = AppNavigationController(rootViewController: bottomNavigationController) let navigationController: AppNavigationController = AppNavigationController(rootViewController: bottomNavigationController)
......
...@@ -42,7 +42,7 @@ class AppMenuController: MenuController { ...@@ -42,7 +42,7 @@ class AppMenuController: MenuController {
/// MenuView inset. /// MenuView inset.
private let menuViewInset: CGFloat = 16 private let menuViewInset: CGFloat = 16
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
...@@ -103,7 +103,7 @@ class AppMenuController: MenuController { ...@@ -103,7 +103,7 @@ class AppMenuController: MenuController {
menuView.animate(MaterialAnimation.animationGroup([ menuView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 3), MaterialAnimation.rotate(rotation: 3),
MaterialAnimation.translateY(0) MaterialAnimation.translateY(0)
])) ]))
} }
/// Hides the menuView. /// Hides the menuView.
...@@ -111,9 +111,9 @@ class AppMenuController: MenuController { ...@@ -111,9 +111,9 @@ class AppMenuController: MenuController {
menuView.animate(MaterialAnimation.animationGroup([ menuView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 3), MaterialAnimation.rotate(rotation: 3),
MaterialAnimation.translateY(150) MaterialAnimation.translateY(150)
])) ]))
} }
/// Prepares the menuView. /// Prepares the menuView.
private func prepareMenuView() { private func prepareMenuView() {
var image: UIImage? = MaterialIcon.cm.add var image: UIImage? = MaterialIcon.cm.add
......
...@@ -39,6 +39,7 @@ class AppNavigationController: NavigationController { ...@@ -39,6 +39,7 @@ class AppNavigationController: NavigationController {
/// Prepares the navigationBar /// Prepares the navigationBar
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
} }
......
...@@ -75,17 +75,8 @@ class ItemViewController: UIViewController { ...@@ -75,17 +75,8 @@ class ItemViewController: UIViewController {
override func viewWillAppear(animated: Bool) { override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
sideNavigationController?.enabled = false sideNavigationController?.enabled = false
// Stops the scrollView contentInsets from being automatically adjusted.
automaticallyAdjustsScrollViewInsets = false
(menuController as? AppMenuController)?.hideMenu()
} }
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
(menuController as? AppMenuController)?.showMenu()
}
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
scrollView.frame = view.bounds scrollView.frame = view.bounds
......
...@@ -35,15 +35,6 @@ class RecipesViewController: UIViewController { ...@@ -35,15 +35,6 @@ class RecipesViewController: UIViewController {
/// A list of all the data source items. /// A list of all the data source items.
private var dataSourceItems: Array<MaterialDataSourceItem>! private var dataSourceItems: Array<MaterialDataSourceItem>!
/// NavigationBar menu button.
private var menuButton: IconButton!
/// NavigationBar switch control.
private var switchControl: MaterialSwitch!
/// NavigationBar search button.
private var searchButton: IconButton!
/// A tableView used to display items. /// A tableView used to display items.
private var tableView: UITableView! private var tableView: UITableView!
...@@ -51,10 +42,6 @@ class RecipesViewController: UIViewController { ...@@ -51,10 +42,6 @@ class RecipesViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareItems() prepareItems()
prepareMenuButton()
prepareSwitchControl()
prepareSearchButton()
prepareNavigationItem()
prepareTableView() prepareTableView()
} }
...@@ -63,45 +50,10 @@ class RecipesViewController: UIViewController { ...@@ -63,45 +50,10 @@ class RecipesViewController: UIViewController {
// Stops the tableView contentInsets from being automatically adjusted. // Stops the tableView contentInsets from being automatically adjusted.
automaticallyAdjustsScrollViewInsets = true automaticallyAdjustsScrollViewInsets = true
// Set the navigationBar style.
navigationController?.navigationBar.statusBarStyle = .LightContent
// Enable the SideNavigation. // Enable the SideNavigation.
sideNavigationController?.enabled = true sideNavigationController?.enabled = true
} }
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// Show the menuView.
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
// Disable the SideNavigation.
// Hide the menuView.
}
/// Handles the menuButton.
internal func handleMenuButton() {
sideNavigationController?.openLeftView()
}
/// Handles the searchButton.
internal func handleSearchButton() {
var recommended: Array<MaterialDataSourceItem> = Array<MaterialDataSourceItem>()
recommended.append(dataSourceItems[1])
recommended.append(dataSourceItems[3])
recommended.append(dataSourceItems[5])
let vc: AppSearchBarController = AppSearchBarController(rootViewController: RecommendationViewController(dataSourceItems: recommended))
vc.modalTransitionStyle = .CrossDissolve
presentViewController(vc, animated: true, completion: nil)
}
/// Prepares the items Array. /// Prepares the items Array.
private func prepareItems() { private func prepareItems() {
dataSourceItems = [ dataSourceItems = [
...@@ -209,42 +161,6 @@ class RecipesViewController: UIViewController { ...@@ -209,42 +161,6 @@ class RecipesViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the menuButton.
private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.cm.menu
menuButton = IconButton()
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
}
/// Prepares the switchControl.
private func prepareSwitchControl() {
switchControl = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
}
/// Prepares the searchButton.
private func prepareSearchButton() {
let image: UIImage? = MaterialIcon.cm.search
searchButton = IconButton()
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
}
/// Prepares the navigationItem.
private func prepareNavigationItem() {
navigationItem.title = "Recipes"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, searchButton]
}
/// Prepares the tableView. /// Prepares the tableView.
private func prepareTableView() { private func prepareTableView() {
tableView = UITableView() tableView = UITableView()
......
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