Commit dd800745 by Daniel Dahan

added NavigationViewController

parent 577c196b
......@@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
9642FA1B1C1B50E700022BC6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */; };
9642FA1D1C1B50E700022BC6 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1C1C1B50E700022BC6 /* MainViewController.swift */; };
9642FA1D1C1B50E700022BC6 /* AppViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1C1C1B50E700022BC6 /* AppViewController.swift */; };
9642FA221C1B50E700022BC6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA211C1B50E700022BC6 /* Assets.xcassets */; };
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* LeftViewController.swift */; };
......@@ -18,6 +18,7 @@
96A71F271C7275F200C0C4AE /* FeedCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F261C7275F200C0C4AE /* FeedCollectionView.swift */; };
96A71F291C72761700C0C4AE /* FeedCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F281C72761700C0C4AE /* FeedCollectionViewLayout.swift */; };
96A71F2B1C72766700C0C4AE /* FeedCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2A1C72766700C0C4AE /* FeedCollectionViewCell.swift */; };
96A71F321C73607B00C0C4AE /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F311C73607B00C0C4AE /* FeedViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -37,7 +38,7 @@
/* 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 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
9642FA1C1C1B50E700022BC6 /* AppViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppViewController.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>"; };
......@@ -47,6 +48,7 @@
96A71F261C7275F200C0C4AE /* FeedCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedCollectionView.swift; sourceTree = "<group>"; };
96A71F281C72761700C0C4AE /* FeedCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedCollectionViewLayout.swift; sourceTree = "<group>"; };
96A71F2A1C72766700C0C4AE /* FeedCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedCollectionViewCell.swift; sourceTree = "<group>"; };
96A71F311C73607B00C0C4AE /* FeedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -82,9 +84,10 @@
isa = PBXGroup;
children = (
9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */,
9642FA1C1C1B50E700022BC6 /* MainViewController.swift */,
9642FA1C1C1B50E700022BC6 /* AppViewController.swift */,
9642FA321C1B909700022BC6 /* LeftViewController.swift */,
967585371C569AA9001E4268 /* RightViewController.swift */,
96A71F311C73607B00C0C4AE /* FeedViewController.swift */,
96A71F261C7275F200C0C4AE /* FeedCollectionView.swift */,
96A71F281C72761700C0C4AE /* FeedCollectionViewLayout.swift */,
96A71F2A1C72766700C0C4AE /* FeedCollectionViewCell.swift */,
......@@ -166,12 +169,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9642FA1D1C1B50E700022BC6 /* MainViewController.swift in Sources */,
9642FA1D1C1B50E700022BC6 /* AppViewController.swift in Sources */,
96A71F271C7275F200C0C4AE /* FeedCollectionView.swift in Sources */,
967585381C569AA9001E4268 /* RightViewController.swift in Sources */,
9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */,
96A71F291C72761700C0C4AE /* FeedCollectionViewLayout.swift in Sources */,
96A71F2B1C72766700C0C4AE /* FeedCollectionViewCell.swift in Sources */,
96A71F321C73607B00C0C4AE /* FeedViewController.swift in Sources */,
9642FA1B1C1B50E700022BC6 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -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(), leftViewController: LeftViewController(), rightViewController: RightViewController())
window!.rootViewController = SideNavigationViewController(mainViewController: AppViewController(mainViewController: FeedViewController()), leftViewController: LeftViewController(), rightViewController: RightViewController())
window!.makeKeyAndVisible()
return true
}
......
......@@ -38,13 +38,7 @@ SideNavigationViewController.
import UIKit
import Material
struct Item {
var title: String
var detail: String
var image: UIImage?
}
class MainViewController: UIViewController {
class AppViewController: NavigationViewController {
/// Menu backdrop layer.
private lazy var menuBackdropLayer: MaterialLayer = MaterialLayer()
......@@ -54,23 +48,12 @@ class MainViewController: UIViewController {
/// MenuView inset.
private let menuViewInset: CGFloat = 16
/// NavigationBarView.
private var navigationBarView: NavigationBarView = NavigationBarView()
/// A tableView used to display Bond entries.
private lazy var collectionView: FeedCollectionView = FeedCollectionView(frame: CGRectNull, collectionViewLayout: FeedCollectionViewLayout())
/// MenuView.
private let menuView: MenuView = MenuView()
/// A list of all the Author Bond types.
var items: Array<Item> = Array<Item>()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareCollectionView()
prepareNavigationBarView()
prepareMenuBackdropLayer()
prepareMenuView()
......@@ -148,62 +131,6 @@ class MainViewController: UIViewController {
view.backgroundColor = MaterialColor.white
}
/// Prepares the items Array.
private func prepareItems() {
items.append(Item(
title: "Raw Vegan Blackberry Tart!",
detail: "Treat yourself today and every day with this sweet nutritious cake!",
image: UIImage(named: "VeganCakeFull")
))
items.append(Item(
title: "Raw Vegan Pumpkin Pie",
detail: "Pumpkin lovers, desert lovers, and anyone who likes simple healthy cooking and enjoys eating! Light up your day with a piece of happiness- raw vegan pumpkin pie :)",
image: UIImage(named: "VeganPieAbove")
))
items.append(Item(
title: "Raw Vegan Nutty Sweets!",
detail: "Since most of my readers have a sweet tooth, here is another simple recipe to boost your happiness :)",
image: UIImage(named: "VeganHempBalls")
))
items.append(Item(
title: "Avocado Chocolate Cake!",
detail: "Do you know what are the two best things about vegan food besides that it's healthy and full of nutrition? It's absolutely delicious and easy to make!",
image: UIImage(named: "AssortmentOfFood")
))
items.append(Item(
title: "Homemade brunch: Crepe Indulgence",
detail: "Looking for a perfect sunday brunch spot? How about staying in and making something to die for?:)",
image: UIImage(named: "AssortmentOfDessert")
))
items.append(Item(
title: "Raw Vegan Chocolate Cookies",
detail: "Once I start making sweets it's hard for me to stop! I've got another exciting recipe, which hopefully you will love! :D",
image: UIImage(named: "HeartCookies")
))
items.append(Item(
title: "Homemade Avocado Ice Cream",
detail: "Avocado ice cream (and vegan!) might not sound so appealing to some of you, but the truth is- it's mind blowing!!!",
image: UIImage(named: "AvocadoIceCream")
))
}
/// Prepares the tableView.
private func prepareCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = MaterialColor.grey.lighten4
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: collectionView, top: navigationBarView.height)
}
/// Prepares the navigationBarView.
private func prepareNavigationBarView() {
// Title label.
......@@ -253,14 +180,13 @@ class MainViewController: UIViewController {
navigationBarView.titleLabel = titleLabel
navigationBarView.leftControls = [menuButton]
navigationBarView.rightControls = [switchControl, searchButton]
view.addSubview(navigationBarView)
}
/// Prepares the menuBackdropLayer.
private func prepareMenuBackdropLayer() {
menuBackdropLayer.backgroundColor = MaterialColor.grey.base.colorWithAlphaComponent(0.75).CGColor
menuBackdropLayer.backgroundColor = MaterialColor.white.colorWithAlphaComponent(0.75).CGColor
menuBackdropLayer.hidden = true
menuBackdropLayer.zPosition = 2000
view.layer.addSublayer(menuBackdropLayer)
}
......@@ -299,47 +225,17 @@ class MainViewController: UIViewController {
menuView.menu.direction = .Up
menuView.menu.baseViewSize = CGSizeMake(menuViewDiameter, menuViewDiameter)
menuView.menu.views = [btn1, btn2, btn3, btn4]
menuView.zPosition = 3000
view.addSubview(menuView)
view.insertSubview(menuView, aboveSubview: navigationBarView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: menuViewDiameter, height: menuViewDiameter)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
}
}
/// UICollectionViewDelegate
extension MainViewController: UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let c: FeedCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("FeedCollectionViewCell", forIndexPath: indexPath) as! FeedCollectionViewCell
let item: Item = items[indexPath.row] as Item
c.titleLabel.text = item.title
c.detailLabel.text = item.detail
c.imageView.image = item.image
return c
}
}
/// UICollectionViewDataSource
extension MainViewController: UICollectionViewDataSource {
//
// :name: numberOfSectionsInTableView
//
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
//
// :name: collectionView
//
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
}
/// SideNavigationViewControllerDelegate methods.
extension MainViewController: SideNavigationViewControllerDelegate {
extension AppViewController: SideNavigationViewControllerDelegate {
/**
An optional delegation method that is fired before the
SideNavigationViewController opens.
......
......@@ -96,19 +96,23 @@ class FeedCollectionViewCell : UICollectionViewCell {
]
titleLabel.grid.rows = 4
titleLabel.grid.columns = 8
titleLabel.grid.columns = 7
titleLabel.grid.offset.columns = 1
moreButton.grid.rows = 3
moreButton.grid.rows = 4
moreButton.grid.columns = 2
moreButton.grid.offset.columns = 10
moreButton.grid.offset.columns = 8
detailLabel.grid.rows = 8
detailLabel.grid.rows = 7
detailLabel.grid.offset.rows = 4
detailLabel.grid.columns = 7
detailLabel.grid.offset.columns = 1
contentView.grid.spacing = 8
contentView.grid.axis.inherited = false
contentView.grid.axis.columns = 10
contentView.grid.axis.direction = .None
contentView.grid.contentInsetPreset = .Square3
contentView.grid.axis.inherited = false
contentView.grid.contentInsetPreset = .Square2
contentView.grid.views = [
titleLabel,
moreButton,
......
......@@ -67,7 +67,7 @@ class FeedCollectionViewLayout : UICollectionViewLayout {
}
override func prepareLayout() {
let dataSource: MainViewController = collectionView!.dataSource as! MainViewController
let dataSource: FeedViewController = collectionView!.dataSource as! FeedViewController
let items: Array<Item> = dataSource.items
layoutItems = Array<(UICollectionViewLayoutAttributes, NSIndexPath)>()
......
/*
* 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 GraphKit 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 MainViewController
within a SideNavigationViewController. There is a NavigationBarView that is
used for navigation, with a menu button that opens the
SideNavigationViewController.
*/
import UIKit
import Material
struct Item {
var title: String
var detail: String
var image: UIImage?
}
class FeedViewController: UIViewController {
/// A tableView used to display Bond entries.
private lazy var collectionView: FeedCollectionView = FeedCollectionView(frame: CGRectNull, collectionViewLayout: FeedCollectionViewLayout())
/// Feed items.
private(set) lazy var items: Array<Item> = Array<Item>()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareCollectionView()
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.white
}
/// Prepares the items Array.
private func prepareItems() {
items.append(Item(
title: "Raw Vegan Blackberry Tart!",
detail: "Treat yourself today and every day with this sweet nutritious cake!",
image: UIImage(named: "VeganCakeFull")
))
items.append(Item(
title: "Raw Vegan Pumpkin Pie",
detail: "Pumpkin lovers, desert lovers, and anyone who likes simple healthy cooking and enjoys eating! Light up your day with a piece of happiness- raw vegan pumpkin pie :)",
image: UIImage(named: "VeganPieAbove")
))
items.append(Item(
title: "Raw Vegan Nutty Sweets!",
detail: "Since most of my readers have a sweet tooth, here is another simple recipe to boost your happiness :)",
image: UIImage(named: "VeganHempBalls")
))
items.append(Item(
title: "Avocado Chocolate Cake!",
detail: "Do you know what are the two best things about vegan food besides that it's healthy and full of nutrition? It's absolutely delicious and easy to make!",
image: UIImage(named: "AssortmentOfFood")
))
items.append(Item(
title: "Homemade brunch: Crepe Indulgence",
detail: "Looking for a perfect sunday brunch spot? How about staying in and making something to die for?:)",
image: UIImage(named: "AssortmentOfDessert")
))
items.append(Item(
title: "Raw Vegan Chocolate Cookies",
detail: "Once I start making sweets it's hard for me to stop! I've got another exciting recipe, which hopefully you will love! :D",
image: UIImage(named: "HeartCookies")
))
items.append(Item(
title: "Homemade Avocado Ice Cream",
detail: "Avocado ice cream (and vegan!) might not sound so appealing to some of you, but the truth is- it's mind blowing!!!",
image: UIImage(named: "AvocadoIceCream")
))
}
/// Prepares the tableView.
private func prepareCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = MaterialColor.grey.lighten4
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: collectionView)
}
}
/// UICollectionViewDelegate
extension FeedViewController: UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let c: FeedCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("FeedCollectionViewCell", forIndexPath: indexPath) as! FeedCollectionViewCell
let item: Item = items[indexPath.row] as Item
c.titleLabel.text = item.title
c.detailLabel.text = item.detail
c.imageView.image = item.image
return c
}
}
/// UICollectionViewDataSource
extension FeedViewController: UICollectionViewDataSource {
/// Number of sections in the collection.
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
/// Number of items in each section.
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
}
......@@ -31,9 +31,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
......
......@@ -41,6 +41,7 @@
96A71EBB1C6FCFA300C0C4AE /* MenuView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71E901C6FBC2200C0C4AE /* MenuView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96A71EC71C6FFF0500C0C4AE /* MaterialSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EC61C6FFF0500C0C4AE /* MaterialSwitch.swift */; };
96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; };
96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
......@@ -141,6 +142,7 @@
96A71E901C6FBC2200C0C4AE /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = "<group>"; };
96A71EC61C6FFF0500C0C4AE /* MaterialSwitch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialSwitch.swift; sourceTree = "<group>"; };
96A71EF51C71127100C0C4AE /* SearchBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarView.swift; sourceTree = "<group>"; };
96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
......@@ -437,6 +439,7 @@
isa = PBXGroup;
children = (
96D88C151C1328D800B91418 /* NavigationBarView.swift */,
96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */,
96D88C1D1C1328D800B91418 /* SideNavigationViewController.swift */,
);
name = Navigation;
......@@ -643,6 +646,7 @@
96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */,
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */,
960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */,
96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */,
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
......
......@@ -69,15 +69,11 @@ Material is a growing project and will encounter changes throughout its developm
## Upcoming
* MenuViewController
* SearchBarViewController
* TabView
* TabViewController
* Scrolling Techniques
* Snackbar
* ProgressBar (circular and horizontal)
* DatePicker
* TimePicker
* More Examples
<a name="materialcolor"></a>
......
......@@ -283,11 +283,11 @@ public class MaterialLayer : CAShapeLayer {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled { [unowned self] in
// self.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
self.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
// removeAnimationForKey(a.keyPath!)
removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: 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
public extension UIViewController {
/**
A convenience property that provides access to the NavigationViewController.
This is the recommended method of accessing the NavigationViewController
through child UIViewControllers.
*/
public var navigationViewController: NavigationViewController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is NavigationViewController {
return viewController as? NavigationViewController
}
viewController = viewController?.parentViewController
}
return nil
}
}
public class NavigationViewController: UIViewController {
public private(set) lazy var navigationBarView: NavigationBarView = NavigationBarView()
/**
A Boolean property used to enable and disable interactivity
with the mainViewController.
*/
public var userInteractionEnabled: Bool {
get {
return mainViewController.view.userInteractionEnabled
}
set(value) {
mainViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it
is recommended to use the transitionFromMainViewController
helper method.
*/
public private(set) var mainViewController: UIViewController!
/**
An initializer for the NavigationViewController.
- Parameter mainViewController: The main UIViewController.
*/
public convenience init(mainViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
prepareView()
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/**
A method to swap mainViewController objects.
- Parameter toViewController: The UIViewController to swap
with the active mainViewController.
- Parameter duration: A NSTimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active mainViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController
to the toViewController has completed.
*/
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval, options: UIViewAnimationOptions, animations: (() -> Void)?, completion: ((Bool) -> Void)?) {
mainViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController)
toViewController.view.frame = view.bounds
transitionFromViewController(mainViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController()
self.mainViewController = toViewController
completion?(result)
})
}
/// A method that generally prepares the NavigationViewController.
private func prepareView() {
prepareNavigationBarView()
prepareMainViewController()
}
/// Prepares the NavigationBarView.
private func prepareNavigationBarView() {
view.addSubview(navigationBarView)
}
/// A method that prepares the mainViewController.
private func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
mainViewController.view.frame = CGRectMake(0, navigationBarView.height, view.bounds.width, view.bounds.height - navigationBarView.height)
mainViewController.view.frame.origin.y = navigationBarView.height
}
/**
A method that adds the passed in controller as a child of
the NavigationViewController within the passed in
container view.
- Parameter viewController: 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(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
container.insertSubview(v.view, atIndex: 0)
v.didMoveToParentViewController(self)
}
}
/// Layout subviews.
private func layoutSubviews() {
}
}
\ No newline at end of file
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