Commit 38e92483 by Daniel Dahan

updated Storyboards NavigationBarView example

parent 3419d84a
...@@ -13,12 +13,9 @@ ...@@ -13,12 +13,9 @@
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; }; 9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* LeftViewController.swift */; }; 9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* LeftViewController.swift */; };
967585381C569AA9001E4268 /* RightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967585371C569AA9001E4268 /* RightViewController.swift */; }; 967585381C569AA9001E4268 /* RightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967585371C569AA9001E4268 /* RightViewController.swift */; };
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 */; };
96A71F3C1C739D1E00C0C4AE /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F3B1C739D1E00C0C4AE /* Material.framework */; }; 96A71F3C1C739D1E00C0C4AE /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F3B1C739D1E00C0C4AE /* Material.framework */; };
96A71F3D1C739D1E00C0C4AE /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F3B1C739D1E00C0C4AE /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 96A71F3D1C739D1E00C0C4AE /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F3B1C739D1E00C0C4AE /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96A71F471C74AD0700C0C4AE /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F461C74AD0700C0C4AE /* FeedViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -44,11 +41,8 @@ ...@@ -44,11 +41,8 @@
9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* LeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftViewController.swift; sourceTree = "<group>"; }; 9642FA321C1B909700022BC6 /* LeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftViewController.swift; sourceTree = "<group>"; };
967585371C569AA9001E4268 /* RightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RightViewController.swift; sourceTree = "<group>"; }; 967585371C569AA9001E4268 /* RightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RightViewController.swift; sourceTree = "<group>"; };
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>"; };
96A71F3B1C739D1E00C0C4AE /* 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>"; }; 96A71F3B1C739D1E00C0C4AE /* 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>"; };
96A71F461C74AD0700C0C4AE /* FeedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -87,10 +81,7 @@ ...@@ -87,10 +81,7 @@
9642FA1C1C1B50E700022BC6 /* AppViewController.swift */, 9642FA1C1C1B50E700022BC6 /* AppViewController.swift */,
9642FA321C1B909700022BC6 /* LeftViewController.swift */, 9642FA321C1B909700022BC6 /* LeftViewController.swift */,
967585371C569AA9001E4268 /* RightViewController.swift */, 967585371C569AA9001E4268 /* RightViewController.swift */,
96A71F311C73607B00C0C4AE /* FeedViewController.swift */, 96A71F461C74AD0700C0C4AE /* FeedViewController.swift */,
96A71F261C7275F200C0C4AE /* FeedCollectionView.swift */,
96A71F281C72761700C0C4AE /* FeedCollectionViewLayout.swift */,
96A71F2A1C72766700C0C4AE /* FeedCollectionViewCell.swift */,
9642FA211C1B50E700022BC6 /* Assets.xcassets */, 9642FA211C1B50E700022BC6 /* Assets.xcassets */,
9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */, 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */,
9642FA261C1B50E700022BC6 /* Info.plist */, 9642FA261C1B50E700022BC6 /* Info.plist */,
...@@ -170,12 +161,9 @@ ...@@ -170,12 +161,9 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9642FA1D1C1B50E700022BC6 /* AppViewController.swift in Sources */, 9642FA1D1C1B50E700022BC6 /* AppViewController.swift in Sources */,
96A71F271C7275F200C0C4AE /* FeedCollectionView.swift in Sources */,
967585381C569AA9001E4268 /* RightViewController.swift in Sources */, 967585381C569AA9001E4268 /* RightViewController.swift in Sources */,
96A71F471C74AD0700C0C4AE /* FeedViewController.swift in Sources */,
9642FA331C1B909700022BC6 /* LeftViewController.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 */, 9642FA1B1C1B50E700022BC6 /* AppDelegate.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.
*/
import UIKit
import Material
class FeedCollectionView : UICollectionView {
//
// :name: init
//
internal required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
//
// :name: init
//
internal override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
prepareView()
}
//
// :name: prepareView
//
internal func prepareView() {
registerClass(FeedCollectionViewCell.self, forCellWithReuseIdentifier: "FeedCollectionViewCell")
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsMake(4, 0, 0, 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.
*/
import UIKit
import Material
class FeedCollectionViewCell : MaterialCollectionViewCell {
let titleLabel: UILabel = UILabel()
let detailLabel: UILabel = UILabel()
let imageView: MaterialView = MaterialView()
var images: Array<UIImage?>?
override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
convenience init() {
self.init(frame: CGRectNull)
prepareView()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func prepareView() {
backgroundColor = MaterialColor.white
pulseScale = false
pulseColor = MaterialColor.blue.lighten4
// var image: UIImage?
contentView.addSubview(imageView)
titleLabel.textColor = MaterialColor.blueGrey.darken4
titleLabel.backgroundColor = MaterialColor.clear
contentView.addSubview(titleLabel)
// image = UIImage(named: "ic_more_vert_white")?.imageWithRenderingMode(.AlwaysTemplate)
// let moreButton: FlatButton = FlatButton()
// moreButton.contentEdgeInsetsPreset = .None
// moreButton.pulseColor = MaterialColor.blueGrey.darken4
// moreButton.tintColor = MaterialColor.blueGrey.darken4
// moreButton.setImage(image, forState: .Normal)
// moreButton.setImage(image, forState: .Highlighted)
// addSubview(moreButton)
// detailLabel.numberOfLines = 0
// detailLabel.lineBreakMode = .ByTruncatingTail
// detailLabel.font = RobotoFont.regularWithSize(12)
// detailLabel.textColor = MaterialColor.blueGrey.darken4
// detailLabel.backgroundColor = MaterialColor.clear
// addSubview(detailLabel)
let g: Int = Int(bounds.width / 48)
switch UIDevice.currentDevice().orientation {
case .LandscapeLeft, .LandscapeRight:
contentView.grid.axis.direction = .None
contentView.grid.columns = g
contentView.grid.views = [
imageView
]
if let v: Array<UIImage?> = images {
let topImageView: MaterialView = MaterialView()
imageView.addSubview(topImageView)
topImageView.image = v.first!
topImageView.grid.rows = 6
topImageView.grid.columns = 6
let bottomImageView: MaterialView = MaterialView()
imageView.addSubview(bottomImageView)
bottomImageView.image = v.last!
bottomImageView.grid.rows = 6
bottomImageView.grid.columns = 6
imageView.grid.views = [
topImageView,
bottomImageView
]
}
default:
for v in imageView.subviews {
v.removeFromSuperview()
}
imageView.contentsGravity = .ResizeAspectFill
imageView.grid.columns = 2
titleLabel.grid.columns = g - 2
// moreButton.grid.rows = 4
// moreButton.grid.columns = 2
// moreButton.grid.offset.columns = 8
detailLabel.grid.rows = 7
detailLabel.grid.offset.rows = 4
detailLabel.grid.columns = 7
detailLabel.grid.offset.columns = 1
// grid.axis.columns = g
// grid.axis.inherited = false
// grid.views = [
// imageView,
// contentView
// ]
contentView.grid.columns = g
contentView.grid.views = [
imageView,
titleLabel
]
}
}
}
/*
* 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
class FeedCollectionViewLayout : UICollectionViewLayout {
private var contentSize: CGSize = CGSizeZero
private var layoutItems: Array<(UICollectionViewLayoutAttributes, NSIndexPath)>?
internal var height: CGFloat = 96
internal var offset: CGFloat = 4
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
switch UIDevice.currentDevice().orientation {
case .LandscapeLeft, .LandscapeRight:
height = UIScreen.mainScreen().bounds.height - 44
default:
height = 96
}
let w: CGFloat = collectionView!.bounds.width
let r: CGFloat = CGFloat(indexPath.row)
attributes.frame = CGRectMake(0, r * CGFloat(height + (0 < r ? offset : 0)), w, height)
return attributes
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
for (attribute, _) in layoutItems! {
if CGRectIntersectsRect(rect, attribute.frame) {
layoutAttributes.append(attribute)
}
}
return layoutAttributes
}
override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return newBounds.width != collectionView!.bounds.width
}
override func collectionViewContentSize() -> CGSize {
return contentSize
}
override func prepareLayout() {
let dataSource: FeedViewController = collectionView!.dataSource as! FeedViewController
let items: Array<Item> = dataSource.items
layoutItems = Array<(UICollectionViewLayoutAttributes, NSIndexPath)>()
var indexPath: NSIndexPath?
var count: Int = 0
for _ in items {
indexPath = NSIndexPath(forItem: count++, inSection: 0)
layoutItems?.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
}
let w: CGFloat = collectionView!.bounds.width
contentSize = CGSizeMake(w, CGFloat(layoutItems!.count) * (height + offset))
}
override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint {
return proposedContentOffset
}
internal func indexPathsOfItemsInRect(rect: CGRect) -> Array<NSIndexPath> {
var paths: Array<NSIndexPath> = Array<NSIndexPath>()
for (attribute, indexPath) in layoutItems! {
if CGRectIntersectsRect(rect, attribute.frame) {
paths.append(indexPath)
}
}
return paths
}
}
...@@ -28,136 +28,123 @@ ...@@ -28,136 +28,123 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 UIKit
import Material import Material
struct Item { private struct Item {
var title: String var text: String
var detail: String var detail: String
var image: UIImage? var image: UIImage?
var images: Array<UIImage?>?
} }
class FeedViewController: UIViewController { class FeedViewController: UIViewController {
/// A tableView used to display Bond entries. /// A tableView used to display Bond entries.
private lazy var collectionView: FeedCollectionView = FeedCollectionView(frame: CGRectNull, collectionViewLayout: FeedCollectionViewLayout()) private let tableView: UITableView = UITableView()
/// Feed items. /// A list of all the Author Bond types.
private(set) lazy var items: Array<Item> = Array<Item>() private var items: Array<Item> = Array<Item>()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareItems() prepareItems()
prepareCollectionView() prepareTableView()
} }
override func viewWillLayoutSubviews() { /**
super.viewWillLayoutSubviews() Handles the search button click, which opens the
collectionView.reloadData() SideNavigationViewController.
*/
func handleSearchButton() {
sideNavigationViewController?.openRightView()
} }
/// Prepares view. /// Prepares view.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the items Array. /// Prepares the items Array.
private func prepareItems() { private func prepareItems() {
items.append(Item( items.append(Item(text: "Summer BBQ", detail: "Wish I could come, but I am out of town this weekend.", image: UIImage(named: "Profile1")))
title: "Raw Vegan Blackberry Tart!", items.append(Item(text: "Birthday gift", detail: "Have any ideas about what we should get Heidi for her birthday?", image: UIImage(named: "Profile2")))
detail: "Treat yourself today and every day with this sweet nutritious cake!", items.append(Item(text: "Brunch this weekend?", detail: "I'll be in your neighborhood doing errands this weekend.", image: UIImage(named: "Profile3")))
image: UIImage(named: "VeganCakeFull"), items.append(Item(text: "Giants game", detail: "Are we on this weekend for the game?", image: UIImage(named: "Profile4")))
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")] items.append(Item(text: "Recipe to try", detail: "We should eat this: Squash, Corn and tomatillo Tacos.", image: UIImage(named: "Profile5")))
)) items.append(Item(text: "Interview", detail: "The candidate will be arriving at 11:30, are you free?", image: UIImage(named: "Profile6")))
items.append(Item(text: "Book recommendation", detail: "I found the book title, Surely You’re Joking, Mr. Feynman!", image: UIImage(named: "Profile7")))
items.append(Item( items.append(Item(text: "Oui oui", detail: "Do you have Paris recommendations? Have you ever been?", image: UIImage(named: "Profile8")))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
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"),
images: [UIImage(named: "VeganCakeFull"), UIImage(named: "VeganCakeFull")]
))
} }
/// Prepares the tableView. /// Prepares the tableView.
private func prepareCollectionView() { private func prepareTableView() {
collectionView.delegate = self tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
collectionView.dataSource = self tableView.dataSource = self
collectionView.backgroundColor = MaterialColor.grey.lighten4 tableView.delegate = self
collectionView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(collectionView) // Use MaterialLayout to easily align the tableView.
MaterialLayout.alignToParent(view, child: collectionView) view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView)
} }
} }
/// UICollectionViewDelegate /// TableViewDataSource methods.
extension FeedViewController: UICollectionViewDelegate { extension FeedViewController: UITableViewDataSource {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { /// Determines the number of rows in the tableView.
let c: FeedCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("FeedCollectionViewCell", forIndexPath: indexPath) as! FeedCollectionViewCell func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count;
}
/// Returns the number of sections.
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
/// Prepares the cells within the tableView.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
let item: Item = items[indexPath.row] as Item let item: Item = items[indexPath.row]
c.titleLabel.text = item.title cell.selectionStyle = .None
c.detailLabel.text = item.detail cell.textLabel!.text = item.text
c.imageView.image = item.image cell.textLabel!.font = RobotoFont.regular
c.images = item.images cell.detailTextLabel!.text = item.detail
c.grid.reloadLayout() cell.detailTextLabel!.font = RobotoFont.regular
cell.detailTextLabel!.textColor = MaterialColor.grey.darken1
cell.imageView!.image = item.image?.resize(toWidth: 40)
cell.imageView!.layer.cornerRadius = 20
return c return cell
}
/// Prepares the header within the tableView.
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView(frame: CGRectMake(0, 0, view.bounds.width, 48))
header.backgroundColor = MaterialColor.white
let label: UILabel = UILabel()
label.font = RobotoFont.medium
label.textColor = MaterialColor.grey.darken1
label.text = "Today"
header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: 24)
return header
} }
} }
/// UICollectionViewDataSource /// UITableViewDelegate methods.
extension FeedViewController: UICollectionViewDataSource { extension FeedViewController: UITableViewDelegate {
/// Number of sections in the collection. /// Sets the tableView cell height.
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 1 return 80
} }
/// Number of items in each section. /// Sets the tableView header height.
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return items.count return 48
} }
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
96A71F4C1C74B1AB00C0C4AE /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F4B1C74B1AB00C0C4AE /* Material.framework */; };
96A71F4D1C74B1AB00C0C4AE /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96A71F4B1C74B1AB00C0C4AE /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9ABEC5151C15085400F6895E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABEC5141C15085400F6895E /* AppDelegate.swift */; }; 9ABEC5151C15085400F6895E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABEC5141C15085400F6895E /* AppDelegate.swift */; };
9ABEC5171C15085400F6895E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABEC5161C15085400F6895E /* ViewController.swift */; }; 9ABEC5171C15085400F6895E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABEC5161C15085400F6895E /* ViewController.swift */; };
9ABEC51A1C15085400F6895E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9ABEC5181C15085400F6895E /* Main.storyboard */; }; 9ABEC51A1C15085400F6895E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9ABEC5181C15085400F6895E /* Main.storyboard */; };
...@@ -21,6 +23,7 @@ ...@@ -21,6 +23,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96A71F4D1C74B1AB00C0C4AE /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -28,6 +31,7 @@ ...@@ -28,6 +31,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
96A71F4B1C74B1AB00C0C4AE /* 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>"; };
9ABEC5111C15085400F6895E /* NavigationBarView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationBarView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9ABEC5111C15085400F6895E /* NavigationBarView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationBarView.app; sourceTree = BUILT_PRODUCTS_DIR; };
9ABEC5141C15085400F6895E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 9ABEC5141C15085400F6895E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9ABEC5161C15085400F6895E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 9ABEC5161C15085400F6895E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
...@@ -42,6 +46,7 @@ ...@@ -42,6 +46,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96A71F4C1C74B1AB00C0C4AE /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -51,6 +56,7 @@ ...@@ -51,6 +56,7 @@
9ABEC5081C15085400F6895E = { 9ABEC5081C15085400F6895E = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96A71F4B1C74B1AB00C0C4AE /* Material.framework */,
9ABEC5131C15085400F6895E /* NavigationBarView */, 9ABEC5131C15085400F6895E /* NavigationBarView */,
9ABEC5121C15085400F6895E /* Products */, 9ABEC5121C15085400F6895E /* Products */,
); );
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--View Controller--> <!--View Controller-->
...@@ -17,19 +17,13 @@ ...@@ -17,19 +17,13 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="est-za-GAc" customClass="NavigationBarView" customModule="Material"> <view contentMode="scaleToFill" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="est-za-GAc" customClass="NavigationBarView" customModule="Material">
<rect key="frame" x="0.0" y="0.0" width="600" height="60"/> <rect key="frame" x="0.0" y="0.0" width="600" height="64"/>
<animations/>
<color key="backgroundColor" red="0.39222975830000001" green="0.2440954615" blue="0.68699765469999996" alpha="1" colorSpace="calibratedRGB"/> <color key="backgroundColor" red="0.39222975830000001" green="0.2440954615" blue="0.68699765469999996" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="bb3-sb-PqQ"/>
</constraints>
</view> </view>
</subviews> </subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints> <constraints>
<constraint firstItem="est-za-GAc" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="2ou-gk-Aka"/>
<constraint firstItem="est-za-GAc" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="AUy-Kc-64K"/> <constraint firstItem="est-za-GAc" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="AUy-Kc-64K"/>
<constraint firstAttribute="trailing" secondItem="est-za-GAc" secondAttribute="trailing" id="y7B-6P-HG1"/> <constraint firstAttribute="trailing" secondItem="est-za-GAc" secondAttribute="trailing" id="y7B-6P-HG1"/>
</constraints> </constraints>
......
...@@ -37,26 +37,18 @@ class ViewController: UIViewController { ...@@ -37,26 +37,18 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
// Examples of using NavigationBarView prepareNavigationBarView()
prepareNavigationBarViewExample()
} }
/** /// General preparation statements.
:name: prepareView
:description: General preparation statements.
*/
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/** /// Prepare the navigationBarView.
:name: prepareNavigationBarViewExample func prepareNavigationBarView() {
:description: General usage example. // Stylize.
*/
func prepareNavigationBarViewExample() {
// Stylize.
navigationBarView.backgroundColor = MaterialColor.indigo.darken1 navigationBarView.backgroundColor = MaterialColor.indigo.darken1
// To lighten the status bar add the "View controller-based status bar appearance = NO" // To lighten the status bar add the "View controller-based status bar appearance = NO"
...@@ -68,10 +60,9 @@ class ViewController: UIViewController { ...@@ -68,10 +60,9 @@ class ViewController: UIViewController {
titleLabel.text = "Material" titleLabel.text = "Material"
titleLabel.textAlignment = .Left titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20) titleLabel.font = RobotoFont.regularWithSize(17)
navigationBarView.titleLabel = titleLabel navigationBarView.titleLabel = titleLabel
navigationBarView.titleLabelInset.left = 64
// Detail label. // Detail label.
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = "Build Beautiful Software" detailLabel.text = "Build Beautiful Software"
...@@ -79,12 +70,11 @@ class ViewController: UIViewController { ...@@ -79,12 +70,11 @@ class ViewController: UIViewController {
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel navigationBarView.detailLabel = detailLabel
navigationBarView.detailLabelInset.left = 64
// Menu button. // Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white") let img1: UIImage? = UIImage(named: "ic_menu_white")
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
btn1.pulseColor = MaterialColor.white btn1.pulseColor = nil
btn1.pulseScale = false btn1.pulseScale = false
btn1.setImage(img1, forState: .Normal) btn1.setImage(img1, forState: .Normal)
btn1.setImage(img1, forState: .Highlighted) btn1.setImage(img1, forState: .Highlighted)
...@@ -92,7 +82,7 @@ class ViewController: UIViewController { ...@@ -92,7 +82,7 @@ class ViewController: UIViewController {
// Star button. // Star button.
let img2: UIImage? = UIImage(named: "ic_star_white") let img2: UIImage? = UIImage(named: "ic_star_white")
let btn2: FlatButton = FlatButton() let btn2: FlatButton = FlatButton()
btn2.pulseColor = MaterialColor.white btn2.pulseColor = nil
btn2.pulseScale = false btn2.pulseScale = false
btn2.setImage(img2, forState: .Normal) btn2.setImage(img2, forState: .Normal)
btn2.setImage(img2, forState: .Highlighted) btn2.setImage(img2, forState: .Highlighted)
...@@ -100,18 +90,16 @@ class ViewController: UIViewController { ...@@ -100,18 +90,16 @@ class ViewController: UIViewController {
// Search button. // Search button.
let img3: UIImage? = UIImage(named: "ic_search_white") let img3: UIImage? = UIImage(named: "ic_search_white")
let btn3: FlatButton = FlatButton() let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.white btn3.pulseColor = nil
btn3.pulseScale = false btn3.pulseScale = false
btn3.setImage(img3, forState: .Normal) btn3.setImage(img3, forState: .Normal)
btn3.setImage(img3, forState: .Highlighted) btn3.setImage(img3, forState: .Highlighted)
// Add buttons to left side. // Add buttons to left side.
navigationBarView.leftButtons = [btn1] navigationBarView.leftControls = [btn1]
// Add buttons to right side. // Add buttons to right side.
navigationBarView.rightButtons = [btn2, btn3] navigationBarView.rightControls = [btn2, btn3]
MaterialLayout.height(view, child: navigationBarView, height: 70)
} }
} }
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
96A71EC71C6FFF0500C0C4AE /* MaterialSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EC61C6FFF0500C0C4AE /* MaterialSwitch.swift */; }; 96A71EC71C6FFF0500C0C4AE /* MaterialSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EC61C6FFF0500C0C4AE /* MaterialSwitch.swift */; };
96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; }; 96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; };
96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */; }; 96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */; };
96A71F351C7395C200C0C4AE /* MaterialCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F341C7395C200C0C4AE /* MaterialCollectionViewCell.swift */; };
96A71F371C73967E00C0C4AE /* MaterialPulseCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F361C73967E00C0C4AE /* MaterialPulseCollectionViewCell.swift */; };
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; }; 96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
...@@ -146,8 +144,6 @@ ...@@ -146,8 +144,6 @@
96A71EC61C6FFF0500C0C4AE /* MaterialSwitch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialSwitch.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>"; }; 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>"; }; 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
96A71F341C7395C200C0C4AE /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; };
96A71F361C73967E00C0C4AE /* MaterialPulseCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseCollectionViewCell.swift; sourceTree = "<group>"; };
96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; }; 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.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>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
...@@ -287,15 +283,6 @@ ...@@ -287,15 +283,6 @@
name = Search; name = Search;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
96A71F331C73959100C0C4AE /* CollectionView */ = {
isa = PBXGroup;
children = (
96A71F361C73967E00C0C4AE /* MaterialPulseCollectionViewCell.swift */,
96A71F341C7395C200C0C4AE /* MaterialCollectionViewCell.swift */,
);
name = CollectionView;
sourceTree = "<group>";
};
96D88BF41C1328D800B91418 /* Sources */ = { 96D88BF41C1328D800B91418 /* Sources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -317,7 +304,6 @@ ...@@ -317,7 +304,6 @@
96D88C471C1328F500B91418 /* Font */, 96D88C471C1328F500B91418 /* Font */,
966F57B61C226D65009185B7 /* Text */, 966F57B61C226D65009185B7 /* Text */,
96442ADC1C28EF1400C3C574 /* TableView */, 96442ADC1C28EF1400C3C574 /* TableView */,
96A71F331C73959100C0C4AE /* CollectionView */,
965C58BD1C6B8D3300CFB4E1 /* Grid */, 965C58BD1C6B8D3300CFB4E1 /* Grid */,
96A71E921C6FBC2900C0C4AE /* Menu */, 96A71E921C6FBC2900C0C4AE /* Menu */,
96A71EC51C6FFEF300C0C4AE /* Switch */, 96A71EC51C6FFEF300C0C4AE /* Switch */,
...@@ -641,7 +627,6 @@ ...@@ -641,7 +627,6 @@
96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */, 96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */,
96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */, 96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */,
96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */, 96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */,
96A71F371C73967E00C0C4AE /* MaterialPulseCollectionViewCell.swift in Sources */,
9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */, 9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */,
960B23461C38480E00E96216 /* Text.swift in Sources */, 960B23461C38480E00E96216 /* Text.swift in Sources */,
96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */, 96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */,
...@@ -680,7 +665,6 @@ ...@@ -680,7 +665,6 @@
960B23331C383EAA00E96216 /* Material+UIImage+Size.swift in Sources */, 960B23331C383EAA00E96216 /* Material+UIImage+Size.swift in Sources */,
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */, 96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */,
96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */, 96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */,
96A71F351C7395C200C0C4AE /* MaterialCollectionViewCell.swift in Sources */,
96D88C271C1328D800B91418 /* Material+UIFont.swift in Sources */, 96D88C271C1328D800B91418 /* Material+UIFont.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.
*/
import UIKit
@objc(MaterialCollectionViewCell)
public class MaterialCollectionViewCell : UICollectionViewCell {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
A base delegate reference used when subclassing MaterialView.
*/
public weak var delegate: MaterialDelegate?
/// Sets whether the scaling animation should be used.
public lazy var pulseScale: Bool = true
/// The opcaity value for the pulse animation.
public var pulseColorOpacity: CGFloat = 0.25
/// The color of the pulse effect.
public var pulseColor: UIColor?
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's backgroundColor.
public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/// A property that accesses the layer.frame.origin.x property.
public var x: CGFloat {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/// A property that accesses the layer.frame.origin.y property.
public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/**
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
if .None != shape {
layer.frame.size.height = value
}
}
}
/**
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
if .None != shape {
layer.frame.size.width = value
}
}
}
/// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .Circle when the cornerRadius is set, it will
become .None, as it no longer maintains its circle shape.
*/
public var cornerRadiusPreset: MaterialRadius {
didSet {
if let v: MaterialRadius = cornerRadiusPreset {
cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
/// A property that accesses the layer.cornerRadius.
public var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
/**
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
frame.size.width = height
} else {
frame.size.height = width
}
}
}
}
/// A property that accesses the layer.borderWith.
public var borderWidth: CGFloat {
didSet {
layer.borderWidth = borderWidth
}
}
/// A property that accesses the layer.borderColor property.
public var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
/// A property that accesses the layer.position property.
public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
depth = .None
cornerRadiusPreset = .None
shape = .None
borderWidth = 0
super.init(coder: aDecoder)
prepareView()
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
depth = .None
cornerRadiusPreset = .None
shape = .None
borderWidth = 0
super.init(frame: frame)
prepareView()
}
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRectNull)
}
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutShape()
layoutVisualLayer()
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
public func animate(animation: CAAnimation) {
animation.delegate = self
if let a: CABasicAnimation = animation as? CABasicAnimation {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
/**
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if anim is CAPropertyAnimation {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
layoutVisualLayer()
}
/**
A delegation method that is executed when the view has began a
touch event.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
pulseAnimation(layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer))
}
/**
A delegation method that is executed when the view touch event has
ended.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
shrinkAnimation()
}
/**
A delegation method that is executed when the view touch event has
been cancelled.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
shrinkAnimation()
}
/**
Triggers the pulse animation.
- Parameter point: A Optional point to pulse from, otherwise pulses
from the center.
*/
public func pulse(var point: CGPoint? = nil) {
if nil == point {
point = CGPointMake(CGFloat(width / 2), CGFloat(height / 2))
}
if let v: CFTimeInterval = pulseAnimation(point!) {
MaterialAnimation.delay(v) { [weak self] in
self?.shrinkAnimation()
}
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
prepareVisualLayer()
shadowColor = MaterialColor.black
borderColor = MaterialColor.black
pulseColor = MaterialColor.white
pulseColorOpacity = 0.25
}
/// Prepares the visualLayer property.
internal func prepareVisualLayer() {
visualLayer.zPosition = 0
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
}
/// Manages the layout for the visualLayer property.
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.backgroundColor = MaterialColor.green.base.CGColor
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
/// Manages the layout for the shape of the view instance.
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
/**
Triggers the pulse animation.
- Parameter point: A point to pulse from.
- Returns: A Ooptional CFTimeInternal if the point exists within
the view. The time internal represents the animation time.
*/
internal func pulseAnimation(point: CGPoint) -> CFTimeInterval? {
if true == layer.containsPoint(point) {
let r: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3
let v: CGFloat = r / f
let d: CGFloat = 2 * f
let s: CGFloat = 1.05
var t: CFTimeInterval = CFTimeInterval(1.5 * width / UIScreen.mainScreen().bounds.width)
if 0.55 < t || 0.25 > t {
t = 0.55
}
t /= 1.3
if nil != pulseColor && 0 < pulseColorOpacity {
let pulseLayer: CAShapeLayer = CAShapeLayer()
pulseLayer.hidden = true
pulseLayer.zPosition = 1
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
visualLayer.addSublayer(pulseLayer)
MaterialAnimation.animationDisabled {
pulseLayer.bounds = CGRectMake(0, 0, v, v)
pulseLayer.position = point
pulseLayer.cornerRadius = r / d
pulseLayer.hidden = false
}
pulseLayer.addAnimation(MaterialAnimation.scale(3 * d, duration: t), forKey: nil)
MaterialAnimation.delay(t) { [weak self] in
if nil != self && nil != self!.pulseColor && 0 < self!.pulseColorOpacity {
MaterialAnimation.animateWithDuration(t, animations: {
pulseLayer.hidden = true
}) {
pulseLayer.removeFromSuperlayer()
}
}
}
}
if pulseScale {
layer.addAnimation(MaterialAnimation.scale(s, duration: t), forKey: nil)
return t
}
}
return nil
}
/// Executes the shrink animation for the pulse effect.
internal func shrinkAnimation() {
if pulseScale {
var t: CFTimeInterval = CFTimeInterval(1.5 * width / UIScreen.mainScreen().bounds.width)
if 0.55 < t || 0.25 > t {
t = 0.55
}
t /= 1.3
layer.addAnimation(MaterialAnimation.scale(1, duration: t), forKey: nil)
}
}
}
\ No newline at end of file
////
//// Copyright (C) 2015 CosmicMind, Inc. <http://cosmicmind.io> and other CosmicMind contributors
////
//// This program is free software: you can redistribute it and/or modify
//// it under the terms of the GNU Affero General Public License as published
//// by the Free Software Foundation, either version 3 of the License, or
//// (at your option) any later version.
////
//// This program is distributed in the hope that it will be useful,
//// but WITHOUT ANY WARRANTY; without even the implied warranty of
//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//// GNU Affero General Public License for more details.
////
//// You should have received a copy of the GNU Affero General Public License
//// along with this program located at the root of the software package
//// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
////
//
//import UIKit
//
//public class MaterialPulseCollectionViewCell : UICollectionViewCell {
// /**
// :name: visualLayer
// */
// public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
//
// /**
// :name: pulseLayer
// */
// public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
//
// /**
// :name: delegate
// */
// public weak var delegate: MaterialDelegate?
//
// /**
// :name: pulseScale
// */
// public lazy var pulseScale: Bool = true
//
// /**
// :name: pulseColorOpacity
// */
// public var pulseColorOpacity: CGFloat = 0.25 {
// didSet {
// updatePulseLayer()
// }
// }
//
// /**
// :name: pulseColor
// */
// public var pulseColor: UIColor? {
// didSet {
// updatePulseLayer()
// }
// }
//
// /**
// :name: image
// */
// public var image: UIImage? {
// didSet {
// visualLayer.contents = image?.CGImage
// }
// }
//
// /**
// :name: contentsRect
// */
// public var contentsRect: CGRect {
// didSet {
// visualLayer.contentsRect = contentsRect
// }
// }
//
// /**
// :name: contentsCenter
// */
// public var contentsCenter: CGRect {
// didSet {
// visualLayer.contentsCenter = contentsCenter
// }
// }
//
// /**
// :name: contentsScale
// */
// public var contentsScale: CGFloat {
// didSet {
// visualLayer.contentsScale = contentsScale
// }
// }
//
// /**
// :name: contentsGravity
// */
// public var contentsGravity: MaterialGravity {
// didSet {
// visualLayer.contentsGravity = MaterialGravityToString(contentsGravity)
// }
// }
//
// /**
// :name: masksToBounds
// */
// public var masksToBounds: Bool {
// get {
// return layer.masksToBounds
// }
// set(value) {
// layer.masksToBounds = value
// }
// }
//
// /**
// :name: backgroundColor
// */
// public override var backgroundColor: UIColor? {
// didSet {
// layer.backgroundColor = backgroundColor?.CGColor
// }
// }
//
// /**
// :name: x
// */
// public var x: CGFloat {
// get {
// return layer.frame.origin.x
// }
// set(value) {
// layer.frame.origin.x = value
// }
// }
//
// /**
// :name: y
// */
// public var y: CGFloat {
// get {
// return layer.frame.origin.y
// }
// set(value) {
// layer.frame.origin.y = value
// }
// }
//
// /**
// :name: width
// */
// public var width: CGFloat {
// get {
// return layer.frame.size.width
// }
// set(value) {
// layer.frame.size.width = value
// if .None != shape {
// layer.frame.size.height = value
// }
// }
// }
//
// /**
// :name: height
// */
// public var height: CGFloat {
// get {
// return layer.frame.size.height
// }
// set(value) {
// layer.frame.size.height = value
// if .None != shape {
// layer.frame.size.width = value
// }
// }
// }
//
// /**
// :name: shadowColor
// */
// public var shadowColor: UIColor? {
// didSet {
// layer.shadowColor = shadowColor?.CGColor
// }
// }
//
// /**
// :name: shadowOffset
// */
// public var shadowOffset: CGSize {
// get {
// return layer.shadowOffset
// }
// set(value) {
// layer.shadowOffset = value
// }
// }
//
// /**
// :name: shadowOpacity
// */
// public var shadowOpacity: Float {
// get {
// return layer.shadowOpacity
// }
// set(value) {
// layer.shadowOpacity = value
// }
// }
//
// /**
// :name: shadowRadius
// */
// public var shadowRadius: CGFloat {
// get {
// return layer.shadowRadius
// }
// set(value) {
// layer.shadowRadius = value
// }
// }
//
// /**
// :name: depth
// */
// public var depth: MaterialDepth {
// didSet {
// let value: MaterialDepthType = MaterialDepthToValue(depth)
// shadowOffset = value.offset
// shadowOpacity = value.opacity
// shadowRadius = value.radius
// }
// }
//
// /**
// :name: cornerRadius
// */
// public var cornerRadius: MaterialRadius? {
// didSet {
// if let v: MaterialRadius = cornerRadius {
// layer.cornerRadius = MaterialRadiusToValue(v)
// if .Circle == shape {
// shape = .None
// }
// }
// }
// }
//
// /**
// :name: shape
// */
// public var shape: MaterialShape {
// didSet {
// if .None != shape {
// if width < height {
// frame.size.width = height
// } else {
// frame.size.height = width
// }
// }
// }
// }
//
// /**
// :name: borderWidth
// */
// public var borderWidth: MaterialBorder {
// didSet {
// layer.borderWidth = MaterialBorderToValue(borderWidth)
// }
// }
//
// /**
// :name: borderColor
// */
// public var borderColor: UIColor? {
// didSet {
// layer.borderColor = borderColor?.CGColor
// }
// }
//
// /**
// :name: position
// */
// public var position: CGPoint {
// get {
// return layer.position
// }
// set(value) {
// layer.position = value
// }
// }
//
// /**
// :name: zPosition
// */
// public var zPosition: CGFloat {
// get {
// return layer.zPosition
// }
// set(value) {
// layer.zPosition = value
// }
// }
//
// /**
// :name: init
// */
// public required init?(coder aDecoder: NSCoder) {
// contentsRect = MaterialTheme.pulseCollectionView.contentsRect
// contentsCenter = MaterialTheme.pulseCollectionView.contentsCenter
// contentsScale = MaterialTheme.pulseCollectionView.contentsScale
// contentsGravity = MaterialTheme.pulseCollectionView.contentsGravity
// borderWidth = MaterialTheme.pulseCollectionView.borderWidth
// depth = MaterialTheme.pulseCollectionView.depth
// shape = .None
// cornerRadius = .None
// super.init(coder: aDecoder)
// prepareView()
// }
//
// /**
// :name: init
// */
// public override init(frame: CGRect) {
// contentsRect = MaterialTheme.pulseCollectionView.contentsRect
// contentsCenter = MaterialTheme.pulseCollectionView.contentsCenter
// contentsScale = MaterialTheme.pulseCollectionView.contentsScale
// contentsGravity = MaterialTheme.pulseCollectionView.contentsGravity
// borderWidth = MaterialTheme.pulseCollectionView.borderWidth
// depth = MaterialTheme.pulseCollectionView.depth
// shape = .None
// cornerRadius = .None
// super.init(frame: frame)
// prepareView()
// }
//
// /**
// :name: init
// */
// public convenience init() {
// self.init(frame: CGRectNull)
// }
//
// /**
// :name: layoutSublayersOfLayer
// */
// public override func layoutSublayersOfLayer(layer: CALayer) {
// super.layoutSublayersOfLayer(layer)
// if self.layer == layer {
// layoutShape()
// layoutVisualLayer()
// }
// }
//
// /**
// :name: animation
// */
// public func animate(animation: CAAnimation) {
// animation.delegate = self
// if let a: CABasicAnimation = animation as? CABasicAnimation {
// a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
// }
// if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
// layer.addAnimation(a, forKey: a.keyPath!)
// } else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
// layer.addAnimation(a, forKey: nil)
// } else if let a: CATransition = animation as? CATransition {
// layer.addAnimation(a, forKey: kCATransition)
// }
// }
//
// /**
// :name: animationDidStart
// */
// public override func animationDidStart(anim: CAAnimation) {
// (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
// }
//
// /**
// :name: animationDidStop
// */
// public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
// if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
// if let b: CABasicAnimation = a as? CABasicAnimation {
// MaterialAnimation.animationDisabled {
// self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
// }
// }
// (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
// layer.removeAnimationForKey(a.keyPath!)
// } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
// for x in a.animations! {
// animationDidStop(x, finished: true)
// }
// }
// }
//
// /**
// :name: touchesBegan
// */
// public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// super.touchesBegan(touches, withEvent: event)
// let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
// if true == layer.containsPoint(point) {
// let w: CGFloat = width
// let h: CGFloat = height
// let s: CGFloat = 1.05
// let t: CFTimeInterval = 0
//
// if nil != pulseColor && 0 < pulseColorOpacity {
// MaterialAnimation.animationDisabled {
// self.pulseLayer.bounds = CGRectMake(0, 0, 2 * w, 2 * h)
// }
// MaterialAnimation.animateWithDuration(t, animations: {
// self.pulseLayer.hidden = false
// })
// }
//
// if pulseScale {
// layer.addAnimation(MaterialAnimation.scale(s, duration: t), forKey: nil)
// }
// }
// }
//
// /**
// :name: touchesEnded
// */
// public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
// super.touchesEnded(touches, withEvent: event)
// shrink()
// }
//
// /**
// :name: touchesCancelled
// */
// public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
// super.touchesCancelled(touches, withEvent: event)
// shrink()
// }
//
// /**
// :name: prepareView
// */
// public func prepareView() {
// prepareVisualLayer()
// preparePulseLayer()
// }
//
// //
// // :name: prepareVisualLayer
// //
// internal func prepareVisualLayer() {
// visualLayer.zPosition = -1
// visualLayer.masksToBounds = true
// layer.addSublayer(visualLayer)
// }
//
// //
// // :name: layoutVisualLayer
// //
// internal func layoutVisualLayer() {
// visualLayer.bounds = bounds
// visualLayer.position = CGPointMake(width / 2, height / 2)
// visualLayer.cornerRadius = layer.cornerRadius
// }
//
// //
// // :name: layoutShape
// //
// internal func layoutShape() {
// if .Circle == shape {
// layer.cornerRadius = width / 2
// }
// }
//
// //
// // :name: preparePulseLayer
// //
// internal func preparePulseLayer() {
// pulseLayer.hidden = true
// pulseLayer.zPosition = 1
// visualLayer.addSublayer(pulseLayer)
// }
//
// //
// // :name: updatePulseLayer
// //
// internal func updatePulseLayer() {
// pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
// }
//
// //
// // :name: shrink
// //
// internal func shrink() {
// let t: CFTimeInterval = 0.25
// let s: CGFloat = 1
//
// if nil != pulseColor && 0 < pulseColorOpacity {
// MaterialAnimation.animateWithDuration(t, animations: {
// self.pulseLayer.hidden = true
// })
// pulseLayer.addAnimation(MaterialAnimation.scale(s, duration: t), forKey: nil)
// }
//
// if pulseScale {
// layer.addAnimation(MaterialAnimation.scale(s, duration: t), forKey: nil)
// }
// }
//}
\ No newline at end of file
...@@ -169,7 +169,13 @@ public class NavigationBarView : MaterialView { ...@@ -169,7 +169,13 @@ public class NavigationBarView : MaterialView {
} }
public override func intrinsicContentSize() -> CGSize { public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(UIScreen.mainScreen().bounds.width, 64) // General alignment.
switch UIDevice.currentDevice().orientation {
case .LandscapeLeft, .LandscapeRight:
return CGSizeMake(UIScreen.mainScreen().bounds.width, 44)
default:
return CGSizeMake(UIScreen.mainScreen().bounds.width, 64)
}
} }
/// Reloads the view. /// Reloads the view.
......
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