Commit 7d7e0975 by Daniel Dahan

working NavigationController -> NavigationBar Back Button

parent 0ff4ab03
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
96334EFC1C8B85F40083986B /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96334EFB1C8B85F40083986B /* Material.framework */; }; 96334EFC1C8B85F40083986B /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96334EFB1C8B85F40083986B /* Material.framework */; };
96334EFD1C8B85F40083986B /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96334EFB1C8B85F40083986B /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 96334EFD1C8B85F40083986B /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96334EFB1C8B85F40083986B /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96334EFF1C8B876E0083986B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96334EFE1C8B876E0083986B /* ViewController.swift */; };
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; }; 9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; };
9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* SearchListViewController.swift */; }; 9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* SearchListViewController.swift */; };
9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; }; 9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; };
...@@ -39,7 +38,6 @@ ...@@ -39,7 +38,6 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
96334EFB1C8B85F40083986B /* 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>"; }; 96334EFB1C8B85F40083986B /* 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>"; };
96334EFE1C8B876E0083986B /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
9663F9311C7A744600AF0965 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 9663F9311C7A744600AF0965 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9663F9331C7A744600AF0965 /* SearchListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchListViewController.swift; sourceTree = "<group>"; }; 9663F9331C7A744600AF0965 /* SearchListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchListViewController.swift; sourceTree = "<group>"; };
...@@ -99,7 +97,6 @@ ...@@ -99,7 +97,6 @@
9663F9381C7A744600AF0965 /* Assets.xcassets */, 9663F9381C7A744600AF0965 /* Assets.xcassets */,
9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */, 9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */,
9663F93D1C7A744600AF0965 /* Info.plist */, 9663F93D1C7A744600AF0965 /* Info.plist */,
96334EFE1C8B876E0083986B /* ViewController.swift */,
); );
path = App; path = App;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -175,7 +172,6 @@ ...@@ -175,7 +172,6 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96334EFF1C8B876E0083986B /* ViewController.swift in Sources */,
9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */, 9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */,
96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */, 96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */,
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */, 9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */,
......
...@@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
// window!.rootViewController = SideNavigationViewController(mainViewController: AppMenuViewController(mainViewController: AppNavigationBarViewController(mainViewController: InboxViewController())), leftViewController: AppLeftViewController(), rightViewController: AppRightViewController()) // window!.rootViewController = SideNavigationViewController(mainViewController: AppMenuViewController(mainViewController: AppNavigationBarViewController(mainViewController: InboxViewController())), leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
window!.rootViewController = NavigationController(rootViewController: FeedViewController()) window!.rootViewController = SideNavigationViewController(mainViewController: NavigationController(rootViewController: FeedViewController()), leftViewController: AppLeftViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -46,7 +46,6 @@ class FeedViewController: UIViewController { ...@@ -46,7 +46,6 @@ class FeedViewController: UIViewController {
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
collectionView.frame = view.bounds
collectionView.reloadData() collectionView.reloadData()
} }
...@@ -59,11 +58,11 @@ class FeedViewController: UIViewController { ...@@ -59,11 +58,11 @@ class FeedViewController: UIViewController {
// Menu button. // Menu button.
let menuButton: FlatButton = FlatButton() let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = MaterialColor.white
menuButton.pulseScale = false menuButton.pulseScale = false
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
// menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside) menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
// Switch control. // Switch control.
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
...@@ -71,18 +70,18 @@ class FeedViewController: UIViewController { ...@@ -71,18 +70,18 @@ class FeedViewController: UIViewController {
// Search button. // Search button.
image = UIImage(named: "ic_search_white") image = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton() let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = MaterialColor.white
searchButton.pulseScale = false searchButton.pulseScale = false
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal) searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
// searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside) searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
navigationController?.navigationBar.leftControls = [menuButton] navigationController?.navigationBar.leftControls = [menuButton]
navigationController?.navigationBar.rightControls = [switchControl, searchButton] navigationController?.navigationBar.rightControls = [switchControl, searchButton]
} }
internal func handleMenuButton() { internal func handleMenuButton() {
print("handled") sideNavigationViewController?.toggleLeftView()
} }
internal func handleSearchButton() { internal func handleSearchButton() {
...@@ -94,7 +93,9 @@ class FeedViewController: UIViewController { ...@@ -94,7 +93,9 @@ class FeedViewController: UIViewController {
view.backgroundColor = MaterialColor.grey.lighten4 view.backgroundColor = MaterialColor.grey.lighten4
navigationController?.navigationBar.statusBarStyle = .LightContent navigationController?.navigationBar.statusBarStyle = .LightContent
navigationController?.navigationBar.tintColor = MaterialColor.white
navigationController?.navigationBar.backgroundColor = MaterialColor.blue.base navigationController?.navigationBar.backgroundColor = MaterialColor.blue.base
navigationController?.navigationBar.backButton.pulseColor = MaterialColor.white
} }
/// Prepares the collectionView /// Prepares the collectionView
...@@ -102,11 +103,12 @@ class FeedViewController: UIViewController { ...@@ -102,11 +103,12 @@ class FeedViewController: UIViewController {
collectionView.dataSource = self collectionView.dataSource = self
collectionView.delegate = self collectionView.delegate = self
collectionView.spacingPreset = .Spacing1 collectionView.spacingPreset = .Spacing1
collectionView.contentInsetPreset = .Square1
collectionView.registerClass(MaterialCollectionViewCell.self, forCellWithReuseIdentifier: "MaterialCollectionViewCell") collectionView.registerClass(MaterialCollectionViewCell.self, forCellWithReuseIdentifier: "MaterialCollectionViewCell")
// To avoid being hidden under the hovering MenuView. // To avoid being hidden under the hovering MenuView.
view.addSubview(collectionView) view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: collectionView)
// collectionView.scrollDirection = .Horizontal // Uncomment to see the horizontal scroll direction. // collectionView.scrollDirection = .Horizontal // Uncomment to see the horizontal scroll direction.
} }
...@@ -204,6 +206,7 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -204,6 +206,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
cardView!.pulseScale = false cardView!.pulseScale = false
cardView!.divider = false cardView!.divider = false
cardView!.depth = .None cardView!.depth = .None
cardView!.cornerRadiusPreset = .None
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.textColor = MaterialColor.grey.darken4 titleLabel.textColor = MaterialColor.grey.darken4
...@@ -246,6 +249,6 @@ extension FeedViewController: MaterialCollectionViewDelegate { ...@@ -246,6 +249,6 @@ extension FeedViewController: MaterialCollectionViewDelegate {
/// Executed when an item is selected. /// Executed when an item is selected.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// print(indexPath) // print(indexPath)
navigationController?.pushViewController(ViewController(), animated: true) navigationController?.pushViewController(InboxViewController(), animated: true)
} }
} }
\ No newline at end of file
...@@ -53,7 +53,10 @@ class InboxViewController: UIViewController { ...@@ -53,7 +53,10 @@ class InboxViewController: UIViewController {
override func viewWillAppear(animated: Bool) { override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
navigationBarViewController?.navigationBarView.titleLabel?.text = "Inbox"
navigationItem.title = "Messages"
navigationController?.navigationBar.topItem?.title = ""
navigationController?.navigationBar.leftControls = []
} }
/** /**
...@@ -135,7 +138,7 @@ extension InboxViewController: UITableViewDataSource { ...@@ -135,7 +138,7 @@ extension InboxViewController: UITableViewDataSource {
header.addSubview(label) header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: navigationBarViewController!.navigationBarView.contentInset.left + navigationBarViewController!.navigationBarView.spacing) MaterialLayout.alignToParent(header, child: label, left: navigationController!.navigationBar.contentInset.left)
return header return header
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
...@@ -30,6 +28,8 @@ ...@@ -30,6 +28,8 @@
<array> <array>
<string>armv7</string> <string>armv7</string>
</array> </array>
<key>UIStatusBarHidden</key>
<false/>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
...@@ -44,5 +44,7 @@ ...@@ -44,5 +44,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict> </dict>
</plist> </plist>
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
The following example shows how to dynamically size MaterialCollectionViewCells.
*/
import UIKit
import Material
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationItem.title = "Material"
navigationController?.navigationBar.leftControls = []
navigationController?.navigationBar.rightControls = []
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.grey.lighten4
}
}
\ No newline at end of file
...@@ -228,7 +228,7 @@ private var GridKey: UInt8 = 0 ...@@ -228,7 +228,7 @@ private var GridKey: UInt8 = 0
/// Grid extension for UIView. /// Grid extension for UIView.
public extension UIView { public extension UIView {
/// Grid reference. /// Grid reference.
public var grid: Grid { public internal(set) var grid: Grid {
get { get {
return MaterialObjectAssociatedObject(self, key: &GridKey) { return MaterialObjectAssociatedObject(self, key: &GridKey) {
return Grid() return Grid()
......
...@@ -67,9 +67,7 @@ public enum MaterialEdgeInset { ...@@ -67,9 +67,7 @@ public enum MaterialEdgeInset {
case TallRectangle9 case TallRectangle9
} }
/** /// Converts the MaterialEdgeInset to a UIEdgeInsets value.
:name: MaterialEdgeInsetToValue
*/
public func MaterialEdgeInsetToValue(inset: MaterialEdgeInset) -> UIEdgeInsets { public func MaterialEdgeInsetToValue(inset: MaterialEdgeInset) -> UIEdgeInsets {
switch inset { switch inset {
case .None: case .None:
...@@ -77,62 +75,62 @@ public func MaterialEdgeInsetToValue(inset: MaterialEdgeInset) -> UIEdgeInsets { ...@@ -77,62 +75,62 @@ public func MaterialEdgeInsetToValue(inset: MaterialEdgeInset) -> UIEdgeInsets {
// square // square
case .Square1: case .Square1:
return UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) return UIEdgeInsetsMake(4, 4, 4, 4)
case .Square2: case .Square2:
return UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) return UIEdgeInsetsMake(8, 8, 8, 8)
case .Square3: case .Square3:
return UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) return UIEdgeInsetsMake(16, 16, 16, 16)
case .Square4: case .Square4:
return UIEdgeInsets(top: 24, left: 24, bottom: 24, right: 24) return UIEdgeInsetsMake(24, 24, 24, 24)
case .Square5: case .Square5:
return UIEdgeInsets(top: 32, left: 32, bottom: 32, right: 32) return UIEdgeInsetsMake(32, 32, 32, 32)
case .Square6: case .Square6:
return UIEdgeInsets(top: 40, left: 40, bottom: 40, right: 40) return UIEdgeInsetsMake(40, 40, 40, 40)
case .Square7: case .Square7:
return UIEdgeInsets(top: 48, left: 48, bottom: 48, right: 48) return UIEdgeInsetsMake(48, 48, 48, 48)
case .Square8: case .Square8:
return UIEdgeInsets(top: 56, left: 56, bottom: 56, right: 56) return UIEdgeInsetsMake(56, 56, 56, 56)
case .Square9: case .Square9:
return UIEdgeInsets(top: 64, left: 64, bottom: 64, right: 64) return UIEdgeInsetsMake(64, 64, 64, 64)
// rectangle // rectangle
case .WideRectangle1: case .WideRectangle1:
return UIEdgeInsets(top: 2, left: 4, bottom: 2, right: 4) return UIEdgeInsetsMake(2, 4, 2, 4)
case .WideRectangle2: case .WideRectangle2:
return UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8) return UIEdgeInsetsMake(4, 8, 4, 8)
case .WideRectangle3: case .WideRectangle3:
return UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16) return UIEdgeInsetsMake(8, 16, 8, 16)
case .WideRectangle4: case .WideRectangle4:
return UIEdgeInsets(top: 12, left: 24, bottom: 12, right: 24) return UIEdgeInsetsMake(12, 24, 12, 24)
case .WideRectangle5: case .WideRectangle5:
return UIEdgeInsets(top: 16, left: 32, bottom: 16, right: 32) return UIEdgeInsetsMake(16, 32, 16, 32)
case .WideRectangle6: case .WideRectangle6:
return UIEdgeInsets(top: 20, left: 40, bottom: 20, right: 40) return UIEdgeInsetsMake(20, 40, 20, 40)
case .WideRectangle7: case .WideRectangle7:
return UIEdgeInsets(top: 24, left: 48, bottom: 24, right: 48) return UIEdgeInsetsMake(24, 48, 24, 48)
case .WideRectangle8: case .WideRectangle8:
return UIEdgeInsets(top: 28, left: 56, bottom: 28, right: 56) return UIEdgeInsetsMake(28, 56, 28, 56)
case .WideRectangle9: case .WideRectangle9:
return UIEdgeInsets(top: 32, left: 64, bottom: 32, right: 64) return UIEdgeInsetsMake(32, 64, 32, 64)
// flipped rectangle // flipped rectangle
case .TallRectangle1: case .TallRectangle1:
return UIEdgeInsets(top: 4, left: 2, bottom: 4, right: 2) return UIEdgeInsetsMake(4, 2, 4, 2)
case .TallRectangle2: case .TallRectangle2:
return UIEdgeInsets(top: 8, left: 4, bottom: 8, right: 4) return UIEdgeInsetsMake(8, 4, 8, 4)
case .TallRectangle3: case .TallRectangle3:
return UIEdgeInsets(top: 16, left: 8, bottom: 16, right: 8) return UIEdgeInsetsMake(16, 8, 16, 8)
case .TallRectangle4: case .TallRectangle4:
return UIEdgeInsets(top: 24, left: 12, bottom: 24, right: 12) return UIEdgeInsetsMake(24, 12, 24, 12)
case .TallRectangle5: case .TallRectangle5:
return UIEdgeInsets(top: 32, left: 16, bottom: 32, right: 16) return UIEdgeInsetsMake(32, 16, 32, 16)
case .TallRectangle6: case .TallRectangle6:
return UIEdgeInsets(top: 40, left: 20, bottom: 40, right: 20) return UIEdgeInsetsMake(40, 20, 40, 20)
case .TallRectangle7: case .TallRectangle7:
return UIEdgeInsets(top: 48, left: 24, bottom: 48, right: 24) return UIEdgeInsetsMake(48, 24, 48, 24)
case .TallRectangle8: case .TallRectangle8:
return UIEdgeInsets(top: 56, left: 28, bottom: 56, right: 28) return UIEdgeInsetsMake(56, 28, 56, 28)
case .TallRectangle9: case .TallRectangle9:
return UIEdgeInsets(top: 64, left: 32, bottom: 64, right: 32) return UIEdgeInsetsMake(64, 32, 64, 32)
} }
} }
...@@ -30,106 +30,6 @@ ...@@ -30,106 +30,6 @@
import UIKit import UIKit
/// A memory reference to the Grid instance for UIView extensions.
private var NavigationBarKey: UInt8 = 0
public class NavigationBarControls {
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets
/// Left controls.
public var leftControls: Array<UIControl>?
/// Right controls.
public var rightControls: Array<UIControl>?
public init() {
contentInsetPreset = .Square2
contentInset = MaterialEdgeInsetToValue(.Square2)
}
}
public extension UINavigationBar {
/// NavigationBarControls reference.
public var controls: NavigationBarControls {
get {
return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) {
return NavigationBarControls()
}
}
set(value) {
MaterialObjectAssociateObject(self, key: &NavigationBarKey, value: value)
}
}
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
public var leftControls: Array<UIControl>? {
get {
return controls.leftControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48, 32)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = -20 + controls.contentInset.left
c.append(spacer)
controls.leftControls = value
topItem?.leftBarButtonItems = c.reverse()
}
}
public var rightControls: Array<UIControl>? {
get {
return controls.rightControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48, 32)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = -20 + controls.contentInset.right
c.append(spacer)
controls.rightControls = value
topItem?.rightBarButtonItems = c.reverse()
}
}
}
public class NavigationBar : UINavigationBar { public class NavigationBar : UINavigationBar {
/** /**
A CAShapeLayer used to manage elements that would be affected by A CAShapeLayer used to manage elements that would be affected by
...@@ -224,43 +124,6 @@ public class NavigationBar : UINavigationBar { ...@@ -224,43 +124,6 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return grid.contentInsetPreset
}
set(value) {
grid.contentInsetPreset = value
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
get {
return grid.contentInset
}
set(value) {
grid.contentInset = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return grid.spacing
}
set(value) {
grid.spacing = value
}
}
/** /**
The back button image writes to the backIndicatorImage property and The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property. backIndicatorTransitionMaskImage property.
...@@ -405,7 +268,6 @@ public class NavigationBar : UINavigationBar { ...@@ -405,7 +268,6 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// A property that sets the cornerRadius of the backing layer. /// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: MaterialRadius = .None { public var cornerRadiusPreset: MaterialRadius = .None {
didSet { didSet {
...@@ -473,29 +335,72 @@ public class NavigationBar : UINavigationBar { ...@@ -473,29 +335,72 @@ public class NavigationBar : UINavigationBar {
} }
} }
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() 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) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() 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 {
layoutVisualLayer()
layoutShadowPath()
}
}
public override func layoutSubviews() {
super.layoutSubviews()
leftControls = leftControls
rightControls = rightControls
if nil != backItem && nil != topItem {
backButton.setImage(backButtonImage, forState: .Normal)
backButton.setImage(backButtonImage, forState: .Highlighted)
leftControls = [backButton]
}
}
/**
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() { public func prepareView() {
translucent = false prepareVisualLayer()
barStyle = .Black barStyle = .Black
translucent = false
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
spacingPreset = .Spacing2 contentInsetPreset = .WideRectangle3
contentInsetPreset = .Square2
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)] titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
prepareVisualLayer() setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
backgroundColor = MaterialColor.white setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
} }
/// Prepares the visualLayer property. /// Prepares the visualLayer property.
...@@ -522,3 +427,168 @@ public class NavigationBar : UINavigationBar { ...@@ -522,3 +427,168 @@ public class NavigationBar : UINavigationBar {
} }
} }
} }
/// A memory reference to the Grid instance for UIView extensions.
private var NavigationBarKey: UInt8 = 0
public class NavigationBarControls {
/// A preset for contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A UIEdgeInsets for contentInset.
public var contentInset: UIEdgeInsets = MaterialEdgeInsetToValue(.None)
/// Preset for spacing value.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// Space between buttons.
public var spacing: CGFloat = 0
/// Inset for spacer button.
public var inset: CGFloat {
return MaterialDevice.landscape ? -20 : -20
}
public private(set) var backButton: MaterialButton
/// Left controls.
public var leftControls: Array<UIControl>?
/// Right controls.
public var rightControls: Array<UIControl>?
public init() {
backButton = FlatButton()
backButton.pulseColor = nil
backButton.pulseScale = false
}
}
public extension UINavigationBar {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// NavigationBarControls reference.
public internal(set) var controls: NavigationBarControls {
get {
return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) {
return NavigationBarControls()
}
}
set(value) {
MaterialObjectAssociateObject(self, key: &NavigationBarKey, value: value)
}
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return controls.contentInsetPreset
}
set(value) {
controls.contentInsetPreset = value
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
get {
return controls.contentInset
}
set(value) {
controls.contentInset = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing {
get {
return controls.spacingPreset
}
set(value) {
controls.spacingPreset = value
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return controls.spacing
}
set(value) {
controls.spacing = value
}
}
/// Back button.
public var backButton: MaterialButton {
return controls.backButton
}
/// Left side UIControls.
public var leftControls: Array<UIControl>? {
get {
return controls.leftControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48 - spacing, 44 - contentInset.top - contentInset.bottom)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = controls.inset + contentInset.left
c.append(spacer)
controls.leftControls = value
topItem?.leftBarButtonItems = c.reverse()
}
}
/// Right side UIControls.
public var rightControls: Array<UIControl>? {
get {
return controls.rightControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48 - spacing, 44 - contentInset.top - contentInset.bottom)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = controls.inset + contentInset.right
c.append(spacer)
controls.rightControls = value
topItem?.rightBarButtonItems = c.reverse()
}
}
}
...@@ -34,26 +34,28 @@ public class NavigationController : UINavigationController { ...@@ -34,26 +34,28 @@ public class NavigationController : UINavigationController {
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
} }
public override init(rootViewController: UIViewController) { public override init(rootViewController: UIViewController) {
super.init(navigationBarClass: NavigationBar.self, toolbarClass: nil) super.init(navigationBarClass: NavigationBar.self, toolbarClass: nil)
setViewControllers([rootViewController], animated: false) setViewControllers([rootViewController], animated: false)
prepareView()
} }
public override func viewDidLoad() { public override func viewWillLayoutSubviews() {
super.viewDidLoad() super.viewWillLayoutSubviews()
prepareView() if let v: NavigationBar = navigationBar as? NavigationBar {
v.layoutSubviews()
v.backButton.removeTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
v.backButton.addTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
}
} }
public func prepareView() { /// Handles the backButton.
navigationItem.title = "Title" internal func handleBackButton() {
popViewControllerAnimated(true)
} }
} }
...@@ -843,12 +843,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -843,12 +843,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
private func toggleStatusBar(hide: Bool = false) { private func toggleStatusBar(hide: Bool = false) {
if hideStatusBar { if hideStatusBar {
UIView.animateWithDuration(0.25, animations: { [weak self] in
// General alignment. // General alignment.
if .iPhone == MaterialDevice.type && MaterialDevice.landscape { if .iPhone == MaterialDevice.type && MaterialDevice.landscape {
UIApplication.sharedApplication().statusBarHidden = true UIApplication.sharedApplication().statusBarHidden = true
} else { } else {
UIApplication.sharedApplication().statusBarHidden = opened ? true : hide UIApplication.sharedApplication().statusBarHidden = true == self?.opened ? true : hide
} }
})
} }
} }
......
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