Commit 75665e13 by Daniel Dahan

updated NavigationBar

parent febee7ec
......@@ -17,9 +17,9 @@
9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; };
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94F1C7A74FC00AF0965 /* AppRightViewController.swift */; };
9663F9521C7A751D00AF0965 /* ItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9511C7A751D00AF0965 /* ItemViewController.swift */; };
96AC822A1C97DE25007654F0 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AC82291C97DE25007654F0 /* Material.framework */; };
96AC822B1C97DE25007654F0 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96AC82291C97DE25007654F0 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96CC08881C7FEBD60034FF84 /* RecipesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */; };
96F2F1B11C979D3B00A5FE27 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96F2F1B01C979D3B00A5FE27 /* Material.framework */; };
96F2F1B21C979D3B00A5FE27 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96F2F1B01C979D3B00A5FE27 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -29,7 +29,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96F2F1B21C979D3B00A5FE27 /* Material.framework in Embed Frameworks */,
96AC822B1C97DE25007654F0 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -49,8 +49,8 @@
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; };
9663F94F1C7A74FC00AF0965 /* AppRightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppRightViewController.swift; sourceTree = "<group>"; };
9663F9511C7A751D00AF0965 /* ItemViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemViewController.swift; sourceTree = "<group>"; };
96AC82291C97DE25007654F0 /* 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>"; };
96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipesViewController.swift; sourceTree = "<group>"; };
96F2F1B01C979D3B00A5FE27 /* 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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -58,7 +58,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96F2F1B11C979D3B00A5FE27 /* Material.framework in Frameworks */,
96AC822A1C97DE25007654F0 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -68,7 +68,7 @@
9663F9251C7A744500AF0965 = {
isa = PBXGroup;
children = (
96F2F1B01C979D3B00A5FE27 /* Material.framework */,
96AC82291C97DE25007654F0 /* Material.framework */,
9663F9301C7A744600AF0965 /* App */,
9663F92F1C7A744600AF0965 /* Products */,
);
......
......@@ -92,8 +92,9 @@ class AppMenuViewController: MenuViewController {
/// Prepares the add button.
private func prepareMenuView() {
var image: UIImage? = UIImage(named: "ic_add_white")
var image: UIImage? = MaterialIcon.add
let menuButton: FabButton = FabButton()
menuButton.tintColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenu", forControlEvents: .TouchUpInside)
......
......@@ -45,12 +45,14 @@ class AppSearchBarController: SearchBarController {
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
searchBar.textField.resignFirstResponder()
sideNavigationController?.enabled = true
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
searchBar.statusBarStyle = .Default
searchBar.textField.becomeFirstResponder()
sideNavigationController?.delegate = self
sideNavigationController?.enabled = false
}
......@@ -87,7 +89,7 @@ class AppSearchBarController: SearchBarController {
clearButton.setImage(image, forState: .Highlighted)
// Back button.
image = MaterialIcon.arrowDownward
image = MaterialIcon.arrowBack
let backButton: FlatButton = FlatButton()
backButton.pulseScale = false
backButton.pulseColor = MaterialColor.grey.darken4
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile1.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile2.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile3.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile4.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile5.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile6.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile7.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile8.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_add_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_add_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_add_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_close_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_close_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_close_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_menu_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_more_horiz_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_more_horiz_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_more_horiz_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_search_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_share_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -147,14 +147,9 @@ class ItemViewController: UIViewController {
imageCardView.detailView = detailLabel
imageCardView.detailViewInset.top = 52
// Asynchronously the load image.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { [weak self] in
if let v: CGFloat = self?.view.bounds.width {
if let v: CGFloat = view.bounds.width {
let image: UIImage? = UIImage(named: data["image"] as! String)?.resize(toWidth: v)?.crop(toWidth: v, toHeight: height)
dispatch_sync(dispatch_get_main_queue()) { [weak self] in
self?.imageCardView.image = image
}
}
imageCardView.image = image
}
view.addSubview(imageCardView)
......
......@@ -84,7 +84,7 @@ class RecipesViewController: UIViewController {
// Hide the menuView.
menuViewController?.menuView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 3),
MaterialAnimation.translateY(100)
MaterialAnimation.translateY(150)
]))
}
......@@ -96,10 +96,13 @@ class RecipesViewController: UIViewController {
/// Handles the searchButton.
internal func handleSearchButton() {
var recommended: Array<MaterialDataSourceItem> = Array<MaterialDataSourceItem>()
recommended.append(dataSourceItems[0])
recommended.append(dataSourceItems[1])
recommended.append(dataSourceItems[2])
navigationController?.presentViewController(AppSearchBarController(mainViewController: RecommendationViewController(dataSourceItems: recommended)), animated: true, completion: nil)
recommended.append(dataSourceItems[3])
recommended.append(dataSourceItems[5])
let vc: AppSearchBarController = AppSearchBarController(mainViewController: RecommendationViewController(dataSourceItems: recommended))
vc.modalTransitionStyle = .CrossDissolve
navigationController?.presentViewController(vc, animated: true, completion: nil)
}
/// Prepares the items Array.
......
......@@ -79,7 +79,7 @@ class AppSearchBarController: SearchBarController {
var image: UIImage? = MaterialIcon.close
let clearButton: FlatButton = FlatButton()
// clearButton.pulseColor = nil
clearButton.pulseColor = nil
clearButton.pulseScale = false
clearButton.tintColor = MaterialColor.blueGrey.darken4
clearButton.setImage(image, forState: .Normal)
......@@ -89,7 +89,7 @@ class AppSearchBarController: SearchBarController {
// Back button.
image = MaterialIcon.arrowBack
let backButton: FlatButton = FlatButton()
// backButton.pulseColor = nil
backButton.pulseColor = nil
backButton.pulseScale = false
backButton.tintColor = MaterialColor.blueGrey.darken4
backButton.setImage(image, forState: .Normal)
......@@ -99,7 +99,7 @@ class AppSearchBarController: SearchBarController {
// More button.
image = MaterialIcon.moreHorizontal
let moreButton: FlatButton = FlatButton()
// moreButton.pulseColor = nil
moreButton.pulseColor = nil
moreButton.pulseScale = false
moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.setImage(image, forState: .Normal)
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_menu_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_search_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ class ViewController: UIViewController {
let menuButton: FlatButton = FlatButton()
menuButton.pulseScale = false
menuButton.pulseColor = MaterialColor.white
menuButton.tintColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
......@@ -81,10 +82,11 @@ class ViewController: UIViewController {
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
// Search button.
image = UIImage(named: "ic_search_white")
image = MaterialIcon.search
let searchButton: FlatButton = FlatButton()
searchButton.pulseScale = false
searchButton.pulseColor = MaterialColor.white
searchButton.tintColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
......@@ -94,7 +96,6 @@ class ViewController: UIViewController {
to your info.plist file and set the following property.
*/
toolbar.statusBarStyle = .LightContent
toolbar.backgroundColor = MaterialColor.blue.base
toolbar.titleLabel = titleLabel
toolbar.detailLabel = detailLabel
......
......@@ -97,6 +97,7 @@ class AppToolbarController: ToolbarController {
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = nil
menuButton.pulseScale = false
menuButton.tintColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
......@@ -106,10 +107,11 @@ class AppToolbarController: ToolbarController {
switchControl.delegate = self
// Search button.
image = UIImage(named: "ic_search_white")
image = MaterialIcon.search
let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = nil
searchButton.pulseScale = false
searchButton.tintColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
......
......@@ -38,6 +38,47 @@ public enum MaterialDeviceType {
}
public struct MaterialDevice {
/// Gets the model name for the device.
public static var model: String {
var systemInfo: utsname = utsname()
uname(&systemInfo)
let machineMirror: Mirror = Mirror(reflecting: systemInfo.machine)
let identifier: String = machineMirror.children.reduce("") { (identifier, element) in
guard let value = element.value as? Int8 where value != 0 else {
return identifier
}
return identifier + String(UnicodeScalar(UInt8(value)))
}
switch identifier {
case "iPod5,1": return "iPod Touch 5"
case "iPod7,1": return "iPod Touch 6"
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4"
case "iPhone4,1": return "iPhone 4s"
case "iPhone5,1", "iPhone5,2": return "iPhone 5"
case "iPhone5,3", "iPhone5,4": return "iPhone 5c"
case "iPhone6,1", "iPhone6,2": return "iPhone 5s"
case "iPhone7,2": return "iPhone 6"
case "iPhone7,1": return "iPhone 6 Plus"
case "iPhone8,1": return "iPhone 6s"
case "iPhone8,2": return "iPhone 6s Plus"
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return "iPad 2"
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad 3"
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad 4"
case "iPad4,1", "iPad4,2", "iPad4,3": return "iPad Air"
case "iPad5,3", "iPad5,4": return "iPad Air 2"
case "iPad2,5", "iPad2,6", "iPad2,7": return "iPad Mini"
case "iPad4,4", "iPad4,5", "iPad4,6": return "iPad Mini 2"
case "iPad4,7", "iPad4,8", "iPad4,9": return "iPad Mini 3"
case "iPad5,1", "iPad5,2": return "iPad Mini 4"
case "iPad6,7", "iPad6,8": return "iPad Pro"
case "AppleTV5,3": return "Apple TV"
case "i386", "x86_64": return "Simulator"
default: return identifier
}
}
/// Retrieves the current device type.
public static var type: MaterialDeviceType {
switch UIDevice.currentDevice().userInterfaceIdiom {
......@@ -62,26 +103,6 @@ public struct MaterialDevice {
return UIApplication.sharedApplication().statusBarOrientation
}
/// Retrieves the device bounds.
public static var bounds: CGRect {
return UIScreen.mainScreen().bounds
}
/// Retrieves the device width.
public static var width: CGFloat {
return bounds.width
}
/// Retrieves the device height.
public static var height: CGFloat {
return bounds.height
}
/// Retrieves the device scale.
public static var scale: CGFloat {
return UIScreen.mainScreen().scale
}
/// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle {
get {
......@@ -101,4 +122,24 @@ public struct MaterialDevice {
UIApplication.sharedApplication().statusBarHidden = value
}
}
/// Retrieves the device bounds.
public static var bounds: CGRect {
return UIScreen.mainScreen().bounds
}
/// Retrieves the device width.
public static var width: CGFloat {
return bounds.width
}
/// Retrieves the device height.
public static var height: CGFloat {
return bounds.height
}
/// Retrieves the device scale.
public static var scale: CGFloat {
return UIScreen.mainScreen().scale
}
}
\ No newline at end of file
......@@ -44,6 +44,12 @@ public extension UINavigationBar {
@IBDesignable
public class NavigationBar : UINavigationBar {
/// Left spacer moves the items to the left edge of the NavigationBar.
private var leftSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
/// Right spacer moves the items to the right edge of the NavigationBar.
private var rightSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
/// Reference to the backButton.
public private(set) lazy var backButton: FlatButton = FlatButton()
......@@ -255,29 +261,13 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() {
super.layoutSubviews()
if let t: UILabel = topItem?.titleLabel {
t.grid.rows = 1
topItem?.titleView?.grid.views = [t]
if 32 >= height || nil == topItem?.detailLabel {
t.font = t.font.fontWithSize(20)
topItem?.titleView?.grid.axis.rows = 1
topItem?.detailLabel?.hidden = true
} else if let d: UILabel = topItem?.detailLabel {
d.grid.rows = 1
d.hidden = false
d.font = d.font.fontWithSize(12)
t.font = t.font.fontWithSize(17)
topItem?.titleView?.grid.axis.rows = 2
topItem?.titleView?.grid.views?.append(d)
}
if let v: UINavigationItem = topItem {
sizeNavigationItem(v)
}
topItem?.titleView?.grid.reloadLayout()
if let v: UINavigationItem = backItem {
sizeNavigationItem(v)
}
}
public override func pushNavigationItem(item: UINavigationItem, animated: Bool) {
......@@ -289,53 +279,42 @@ public class NavigationBar : UINavigationBar {
Lays out the UINavigationItem.
- Parameter item: A UINavigationItem to layout.
*/
public func layoutNavigationItem(item: UINavigationItem) {
internal func layoutNavigationItem(item: UINavigationItem) {
prepareItem(item)
let h: CGFloat = intrinsicContentSize().height
let w: CGFloat = backButton.intrinsicContentSize().width
let inset: CGFloat = item.inset
// leftControls
if let v: Array<UIControl> = item.leftControls {
var n: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
for c in v {
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets.top = 0
b.contentEdgeInsets.bottom = 0
}
c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
n.append(UIBarButtonItem(customView: c))
}
// The spacer moves the UIBarButtonItems to the edge of the UINavigationBar.
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = inset + contentInset.left
n.append(spacer)
n.append(leftSpacer)
item.leftBarButtonItems = n.reverse()
}
// Set the titleView if title is empty.
if "" == item.title {
if nil == item.titleView {
item.titleView = UIView(frame: CGRectMake(0, contentInset.top, MaterialDevice.width, h - contentInset.top - contentInset.bottom))
item.titleView!.autoresizingMask = .FlexibleWidth
item.titleView = UIView(frame: CGRectMake(0, contentInset.top, MaterialDevice.width < MaterialDevice.height ? MaterialDevice.height : MaterialDevice.width, intrinsicContentSize().height - contentInset.top - contentInset.bottom))
item.titleView!.autoresizingMask = [.FlexibleWidth]
item.titleView!.grid.axis.direction = .Vertical
}
item.titleView!.backgroundColor = MaterialColor.green.base
// TitleView alignment.
if let t: UILabel = item.titleLabel {
t.grid.rows = 1
item.titleView!.addSubview(t)
if let d: UILabel = item.detailLabel {
d.hidden = false
d.grid.rows = 1
item.titleView!.addSubview(d)
item.titleView!.grid.views = [t, d]
} else {
item.detailLabel?.hidden = true
item.titleView!.grid.views = [t]
}
} else if let d: UIView = item.detailView {
d.grid.rows = 1
item.titleView!.addSubview(d)
item.titleView!.grid.views = [d]
}
}
......@@ -343,20 +322,67 @@ public class NavigationBar : UINavigationBar {
if let v: Array<UIControl> = item.rightControls {
var n: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
for c in v {
n.append(UIBarButtonItem(customView: c))
}
n.append(rightSpacer)
item.rightBarButtonItems = n.reverse()
}
sizeNavigationItem(item)
}
/**
Sizes the UINavigationItem.
- Parameter item: A UINavigationItem to size.
*/
internal func sizeNavigationItem(item: UINavigationItem) {
let h: CGFloat = intrinsicContentSize().height
let w: CGFloat = backButton.intrinsicContentSize().width
let inset: CGFloat = MaterialDevice.landscape ? item.landscapeInset : item.portraitInset
// leftControls
if let v: Array<UIControl> = item.leftControls {
for c in v {
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets.top = 0
b.contentEdgeInsets.bottom = 0
}
c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
n.append(UIBarButtonItem(customView: c))
}
leftSpacer.width = inset + contentInset.left
}
// The spacer moves the UIBarButtonItems to the edge of the UINavigationBar.
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = inset + contentInset.right
n.append(spacer)
item.titleView?.frame.size.height = height - contentInset.top - contentInset.bottom
item.rightBarButtonItems = n.reverse()
if let t: UILabel = item.titleLabel {
if 32 >= height || nil == item.detailLabel {
t.font = t.font.fontWithSize(20)
item.detailLabel?.hidden = true
item.titleView?.grid.axis.rows = 1
} else if let d: UILabel = item.detailLabel {
t.font = t.font.fontWithSize(17)
d.hidden = false
d.font = d.font.fontWithSize(12)
item.titleView?.grid.axis.rows = 2
}
} else if let _: UIView = item.detailView {
item.titleView?.grid.axis.rows = 1
}
// rightControls
if let v: Array<UIControl> = item.rightControls {
for c in v {
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets.top = 0
b.contentEdgeInsets.bottom = 0
}
c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
}
rightSpacer.width = inset + contentInset.right
}
}
......
......@@ -35,7 +35,9 @@ private var NavigationItemKey: UInt8 = 0
public class NavigationItem {
/// Inset.
public var inset: CGFloat = -20
public var portraitInset: CGFloat
public var landscapeInset: CGFloat
/// Detail View.
public var detailView: UIView?
......@@ -51,6 +53,11 @@ public class NavigationItem {
/// Right controls.
public var rightControls: Array<UIControl>?
public init(portraitInset: CGFloat, landscapeInset: CGFloat) {
self.portraitInset = portraitInset
self.landscapeInset = landscapeInset
}
}
public extension UINavigationItem {
......@@ -58,7 +65,7 @@ public extension UINavigationItem {
public internal(set) var item: NavigationItem {
get {
return MaterialAssociatedObject(self, key: &NavigationItemKey) {
return NavigationItem()
return NavigationItem(portraitInset: .iPad == MaterialDevice.type || "iPhone 6s Plus" == MaterialDevice.model || "iPhone 6 Plus" == MaterialDevice.model ? -20 : -16, landscapeInset: -20)
}
}
set(value) {
......@@ -66,13 +73,23 @@ public extension UINavigationItem {
}
}
/// Inset.
public var inset: CGFloat {
/// Portrait inset.
public var portraitInset: CGFloat {
get {
return item.portraitInset
}
set(value) {
item.portraitInset = value
}
}
/// Landscape inset.
public var landscapeInset: CGFloat {
get {
return item.inset
return item.landscapeInset
}
set(value) {
item.inset = value
item.landscapeInset = value
}
}
......
......@@ -305,12 +305,6 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
layoutSubviews()
}
public override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
if let v: MaterialView = rightView {
v.x = view.bounds.height - (openedRightView ? rightViewWidth : 0)
}
}
/**
A method to swap mainViewController objects.
- Parameter toViewController: The UIViewController to swap
......@@ -557,7 +551,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
animations: {
v.position.x = -v.width / 2
}) { [unowned self] _ in
self.toggleStatusBar()
self.toggleStatusBar(MaterialDevice.landscape && .iPhone == MaterialDevice.type)
self.hideView(v)
self.delegate?.sideNavigationDidClose?(self, position: .Left)
}
......@@ -580,7 +574,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
animations: { [unowned self] in
v.position.x = self.view.bounds.width + v.width / 2
}) { [unowned self] _ in
self.toggleStatusBar()
self.toggleStatusBar(MaterialDevice.landscape && .iPhone == MaterialDevice.type)
self.hideView(v)
self.delegate?.sideNavigationDidClose?(self, position: .Right)
}
......@@ -833,20 +827,20 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
the status bar.
*/
private func toggleStatusBar(hide: Bool = false) {
if hideStatusBar {
userInteractionEnabled = false
let hidden: Bool = .iPhone == MaterialDevice.type && MaterialDevice.landscape || opened ? true : hide
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in
self?.setNeedsStatusBarAppearanceUpdate()
MaterialDevice.statusBarHidden = hidden
}) { [weak self] _ in
if false == self?.opened {
self?.userInteractionEnabled = true
}
}
delegate?.sideNavigationStatusBarHiddenState?(self, hidden: hidden)
}
// if hideStatusBar {
// userInteractionEnabled = false
// let hidden: Bool = opened ? true : hide
// UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
// animations: { [weak self] in
// self?.setNeedsStatusBarAppearanceUpdate()
// MaterialDevice.statusBarHidden = hidden
// }) { [weak self] _ in
// if false == self?.opened {
// self?.userInteractionEnabled = true
// }
// }
// delegate?.sideNavigationStatusBarHiddenState?(self, hidden: hidden)
// }
}
public override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
......@@ -915,7 +909,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
/// Layout subviews.
private func layoutSubviews() {
toggleStatusBar()
toggleStatusBar(MaterialDevice.landscape && .iPhone == MaterialDevice.type)
if let v: MaterialView = leftView {
v.width = leftViewWidth
......
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