Commit 2be8f826 by Daniel Dahan

updated NavigationDrawerController project

parent 85dae35e
......@@ -7,6 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
967A48071D0E0EA300B8CEB7 /* AppRightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967A48061D0E0EA300B8CEB7 /* AppRightViewController.swift */; };
967A48091D0E127200B8CEB7 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 967A48081D0E127200B8CEB7 /* Material.framework */; };
967A480A1D0E127200B8CEB7 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 967A48081D0E127200B8CEB7 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96CB75011D0DFDBB0012D9F2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CB75001D0DFDBB0012D9F2 /* AppDelegate.swift */; };
96CB75031D0DFDBB0012D9F2 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CB75021D0DFDBB0012D9F2 /* AppLeftViewController.swift */; };
96CB75081D0DFDBB0012D9F2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96CB75071D0DFDBB0012D9F2 /* Assets.xcassets */; };
......@@ -25,6 +28,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
967A480A1D0E127200B8CEB7 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -32,6 +36,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
967A48061D0E0EA300B8CEB7 /* AppRightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppRightViewController.swift; sourceTree = "<group>"; };
967A48081D0E127200B8CEB7 /* 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>"; };
96CB74FD1D0DFDBB0012D9F2 /* NavigationDrawerController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationDrawerController.app; sourceTree = BUILT_PRODUCTS_DIR; };
96CB75001D0DFDBB0012D9F2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96CB75021D0DFDBB0012D9F2 /* AppLeftViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; };
......@@ -50,6 +56,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
967A48091D0E127200B8CEB7 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -59,6 +66,7 @@
96CB74F41D0DFDBB0012D9F2 = {
isa = PBXGroup;
children = (
967A48081D0E127200B8CEB7 /* Material.framework */,
96CB74FF1D0DFDBB0012D9F2 /* NavigationDrawerController */,
96CB74FE1D0DFDBB0012D9F2 /* Products */,
);
......@@ -77,6 +85,7 @@
children = (
96CB75001D0DFDBB0012D9F2 /* AppDelegate.swift */,
96CB75021D0DFDBB0012D9F2 /* AppLeftViewController.swift */,
967A48061D0E0EA300B8CEB7 /* AppRightViewController.swift */,
96CB75121D0DFF6F0012D9F2 /* YellowViewController.swift */,
96CB75141D0DFF840012D9F2 /* BlueViewController.swift */,
96CB75161D0DFF9C0012D9F2 /* GreenViewController.swift */,
......@@ -165,6 +174,7 @@
96CB75191D0DFFAE0012D9F2 /* PurpleViewController.swift in Sources */,
96CB75151D0DFF840012D9F2 /* BlueViewController.swift in Sources */,
96CB75011D0DFDBB0012D9F2 /* AppDelegate.swift in Sources */,
967A48071D0E0EA300B8CEB7 /* AppRightViewController.swift in Sources */,
96CB751B1D0DFFC10012D9F2 /* OrangeViewController.swift in Sources */,
96CB75171D0DFF9C0012D9F2 /* GreenViewController.swift in Sources */,
);
......
......@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let navigationController: NavigationController = NavigationController(rootViewController: YellowViewController())
let navigationDrawerController: NavigationDrawerController = NavigationDrawerController(rootViewController: navigationController, leftViewController: AppLeftViewController())
let navigationDrawerController: NavigationDrawerController = NavigationDrawerController(rootViewController: navigationController, leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
// navigationDrawerController.enabled = true
//
......
/*
* 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.
*/
import UIKit
import Material
class AppRightViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.grey.darken4
}
}
......@@ -38,8 +38,8 @@ class YellowViewController: UIViewController {
/// NavigationBar switch control.
private var switchControl: MaterialSwitch!
/// NavigationBar search button.
private var searchButton: IconButton!
/// NavigationBar more button.
private var moreButton: IconButton!
override func viewDidLoad() {
super.viewDidLoad()
......@@ -60,6 +60,10 @@ class YellowViewController: UIViewController {
navigationDrawerController?.openLeftView()
}
internal func handleMoreButton() {
navigationDrawerController?.openRightView()
}
/// Prepares the view.
private func prepareView() {
view.backgroundColor = MaterialColor.yellow.base
......@@ -82,11 +86,12 @@ class YellowViewController: UIViewController {
/// 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)
let image: UIImage? = MaterialIcon.cm.moreVertical
moreButton = IconButton()
moreButton.pulseColor = MaterialColor.white
moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted)
moreButton.addTarget(self, action: #selector(handleMoreButton), forControlEvents: .TouchUpInside)
}
/// Prepares the navigationItem.
......@@ -96,7 +101,7 @@ class YellowViewController: UIViewController {
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, searchButton]
navigationItem.rightControls = [switchControl, moreButton]
}
/// Prepares the navigationBar.
......
......@@ -145,8 +145,6 @@ public class BarController : UIViewController {
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view)
}
......@@ -161,9 +159,11 @@ public class BarController : UIViewController {
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self)
}
}
}
......@@ -196,8 +196,6 @@ public class MenuController : UIViewController {
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view)
}
......@@ -212,9 +210,11 @@ public class MenuController : UIViewController {
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self)
}
}
......
......@@ -400,12 +400,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
// Portrait will be Lanscape when this method is done.
if MaterialDevice.isPortrait && .iPhone == MaterialDevice.type {
hideStatusBar()
} else {
showStatusBar()
}
closeLeftView()
closeRightView()
......@@ -725,7 +719,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
public func closeRightView(velocity: CGFloat = 0) {
if enabledRightView {
if let v: MaterialView = rightView {
showStatusBar()
userInteractionEnabled = true
delegate?.navigationDrawerWillClose?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
......@@ -841,7 +834,7 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
let a: CGFloat = 1 - (view.bounds.width - v.position.x) / v.width
rootViewController.view.alpha = 0.5 < a && v.position.x >= v.width / 2 ? a : 0.5
if translationX <= view.bounds.width - rightThreshold {
if translationX <= -rightThreshold {
hideStatusBar()
}
......@@ -914,17 +907,12 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.frame = view.bounds
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view)
}
/// A method that prepares the leftViewController.
private func prepareLeftViewController() {
if let v: MaterialView = leftView {
leftViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(leftViewController, container: v)
prepareLeftViewGestures()
}
......@@ -933,8 +921,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
/// A method that prepares the rightViewController.
private func prepareRightViewController() {
if let v: MaterialView = rightView {
rightViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rightViewController, container: v)
prepareRightViewGestures()
}
......@@ -991,9 +977,11 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self)
}
}
......@@ -1098,8 +1086,8 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
willHideStatusBar = false
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in
self?.setNeedsStatusBarAppearanceUpdate()
self?.statusBarHidden = false
self?.setNeedsStatusBarAppearanceUpdate()
})
delegate?.navigationDrawerStatusBarHiddenState?(self, hidden: false)
}
......@@ -1112,8 +1100,8 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
if !statusBarHidden {
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in
self?.setNeedsStatusBarAppearanceUpdate()
self?.statusBarHidden = true
self?.setNeedsStatusBarAppearanceUpdate()
})
delegate?.navigationDrawerStatusBarHiddenState?(self, hidden: true)
}
......
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