Commit 3cd654d4 by Daniel Dahan

preparing NavigationController example

parent 173ffa96
...@@ -45,99 +45,3 @@ class AppNavigationController: NavigationController { ...@@ -45,99 +45,3 @@ class AppNavigationController: NavigationController {
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
} }
} }
//class AppNavigationBarViewController: NavigationBarViewController {
// override var floatingViewController: UIViewController? {
// didSet {
// if nil == floatingViewController {
// navigationBarView.statusBarStyle = .LightContent
// }
// }
// }
//
// override func viewDidLoad() {
// super.viewDidLoad()
// prepareView()
// prepareNavigationBarView()
// }
//
// override func viewWillAppear(animated: Bool) {
// super.viewWillAppear(animated)
// navigationBarView.statusBarStyle = .LightContent
// }
//
// /// Prepares view.
// override func prepareView() {
// super.prepareView()
// view.backgroundColor = MaterialColor.black
// navigationBarViewController?.delegate = self
// }
//
// /// Toggle SideNavigationViewController left UIViewController.
// internal func handleMenuButton() {
// sideNavigationViewController?.toggleLeftView()
// }
//
// /// Toggle SideNavigationViewController right UIViewController.
// internal func handleSearchButton() {
// floatingViewController = AppSearchBarViewController(mainViewController: SearchListViewController())
// }
//
// /// Prepares the navigationBarView.
// private func prepareNavigationBarView() {
// // Title label.
// let titleLabel: UILabel = UILabel()
// titleLabel.textAlignment = .Left
// titleLabel.textColor = MaterialColor.white
//
// var image = UIImage(named: "ic_menu_white")
//
// // Menu button.
// let menuButton: FlatButton = FlatButton()
// menuButton.pulseColor = MaterialColor.white
// menuButton.pulseScale = false
// menuButton.setImage(image, forState: .Normal)
// menuButton.setImage(image, forState: .Highlighted)
// menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
//
// // Switch control.
// let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
//
// // Search button.
// image = UIImage(named: "ic_search_white")
// let searchButton: FlatButton = FlatButton()
// searchButton.pulseColor = MaterialColor.white
// searchButton.pulseScale = false
// searchButton.setImage(image, forState: .Normal)
// searchButton.setImage(image, forState: .Highlighted)
// searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
//
// navigationBarView.backgroundColor = MaterialColor.blue.base
// navigationBarView.titleLabel = titleLabel
// navigationBarView.leftControls = [menuButton]
// navigationBarView.rightControls = [switchControl, searchButton]
// }
//}
//
//
//extension AppNavigationBarViewController: NavigationBarViewControllerDelegate {
// /// Delegation method that executes when the floatingViewController will open.
// func navigationBarViewControllerWillOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Will Open")
// }
//
// /// Delegation method that executes when the floatingViewController will close.
// func navigationBarViewControllerWillCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Will Close")
// }
//
// /// Delegation method that executes when the floatingViewController did open.
// func navigationBarViewControllerDidOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Did Open")
// }
//
// /// Delegation method that executes when the floatingViewController did close.
// func navigationBarViewControllerDidCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Did Close")
// }
//}
...@@ -47,80 +47,14 @@ public class NavigationBar : UINavigationBar { ...@@ -47,80 +47,14 @@ public class NavigationBar : UINavigationBar {
public private(set) lazy var backButton: FlatButton = FlatButton() public private(set) lazy var backButton: FlatButton = FlatButton()
/** /**
A CAShapeLayer used to manage elements that would be affected by The back button image writes to the backIndicatorImage property and
the clipToBounds property of the backing layer. For example, this backIndicatorTransitionMaskImage property.
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 property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
property to avoid conflicts when using clipsToBounds.
*/
public var image: UIImage? {
didSet {
visualLayer.contents = image?.CGImage
}
}
/**
Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows
much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched.
*/
public var contentsRect: CGRect {
get {
return visualLayer.contentsRect
}
set(value) {
visualLayer.contentsRect = value
}
}
/**
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
*/
public var contentsCenter: CGRect {
get {
return visualLayer.contentsCenter
}
set(value) {
visualLayer.contentsCenter = value
}
}
/**
A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the MaterialDevice.scale.
*/ */
public var contentsScale: CGFloat { public var backButtonImage: UIImage? {
get {
return visualLayer.contentsScale
}
set(value) {
visualLayer.contentsScale = value
}
}
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet { didSet {
contentsGravity = MaterialGravityToString(contentsGravityPreset) if nil == backButtonImage {
} backButtonImage = UIImage(named: "ic_arrow_back_white", inBundle: NSBundle(identifier: "io.cosmicmind.Material"), compatibleWithTraitCollection: nil)
} }
/// Determines how content should be aligned within the visualLayer's bounds.
public var contentsGravity: String {
get {
return visualLayer.contentsGravity
}
set(value) {
visualLayer.contentsGravity = value
} }
} }
...@@ -139,18 +73,6 @@ public class NavigationBar : UINavigationBar { ...@@ -139,18 +73,6 @@ public class NavigationBar : UINavigationBar {
} }
} }
/**
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
*/
public var backButtonImage: UIImage? {
didSet {
if nil == backButtonImage {
backButtonImage = UIImage(named: "ic_arrow_back_white", inBundle: NSBundle(identifier: "io.cosmicmind.Material"), compatibleWithTraitCollection: nil)
}
}
}
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
didSet { didSet {
...@@ -259,25 +181,6 @@ public class NavigationBar : UINavigationBar { ...@@ -259,25 +181,6 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: MaterialRadius = .None {
didSet {
if let v: MaterialRadius = cornerRadiusPreset {
cornerRadius = MaterialRadiusToValue(v)
}
}
}
/// A property that accesses the layer.cornerRadius.
public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set(value) {
layer.cornerRadius = value
}
}
/// A preset property to set the borderWidth. /// A preset property to set the borderWidth.
public var borderWidthPreset: MaterialBorder = .None { public var borderWidthPreset: MaterialBorder = .None {
didSet { didSet {
...@@ -305,32 +208,11 @@ public class NavigationBar : UINavigationBar { ...@@ -305,32 +208,11 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// 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. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
} }
...@@ -342,7 +224,6 @@ public class NavigationBar : UINavigationBar { ...@@ -342,7 +224,6 @@ public class NavigationBar : UINavigationBar {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
...@@ -352,14 +233,6 @@ public class NavigationBar : UINavigationBar { ...@@ -352,14 +233,6 @@ public class NavigationBar : UINavigationBar {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
} }
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutVisualLayer()
}
}
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
...@@ -370,6 +243,10 @@ public class NavigationBar : UINavigationBar { ...@@ -370,6 +243,10 @@ public class NavigationBar : UINavigationBar {
topItem?.titleView?.grid.reloadLayout() topItem?.titleView?.grid.reloadLayout()
} }
/**
Lays out the UINavigationItem.
- Parameter item: A UINavigationItem to layout.
*/
public func layoutNavigationItem(item: UINavigationItem) { public func layoutNavigationItem(item: UINavigationItem) {
// leftControls // leftControls
if let v: Array<UIControl> = item.leftControls { if let v: Array<UIControl> = item.leftControls {
...@@ -378,14 +255,17 @@ public class NavigationBar : UINavigationBar { ...@@ -378,14 +255,17 @@ public class NavigationBar : UINavigationBar {
c.bounds.size = c is MaterialSwitch ? backButton.bounds.size : c.intrinsicContentSize() c.bounds.size = c is MaterialSwitch ? backButton.bounds.size : c.intrinsicContentSize()
n.append(UIBarButtonItem(customView: c)) 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) let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = item.inset spacer.width = item.inset
n.append(spacer) n.append(spacer)
item.leftBarButtonItems = n.reverse() item.leftBarButtonItems = n.reverse()
} }
if nil == item.titleView { if nil == item.titleView {
item.titleView = UIView(frame: CGRectMake(0, 0, 2000, 44)) item.titleView = UIView(frame: CGRectMake(0, 2, MaterialDevice.width < MaterialDevice.height ? MaterialDevice.height : MaterialDevice.width, 40))
item.titleView!.backgroundColor = nil item.titleView!.backgroundColor = nil
item.titleView!.grid.axis.direction = .Vertical item.titleView!.grid.axis.direction = .Vertical
} }
...@@ -395,14 +275,12 @@ public class NavigationBar : UINavigationBar { ...@@ -395,14 +275,12 @@ public class NavigationBar : UINavigationBar {
// TitleView alignment. // TitleView alignment.
if let t: UILabel = item.titleLabel { if let t: UILabel = item.titleLabel {
t.grid.rows = 1 t.grid.rows = 1
t.backgroundColor = MaterialColor.red.accent1
item.titleView!.addSubview(t) item.titleView!.addSubview(t)
item.titleView!.grid.views?.append(t) item.titleView!.grid.views?.append(t)
if let d: UILabel = item.detailLabel { if let d: UILabel = item.detailLabel {
d.backgroundColor = MaterialColor.red.accent3
t.font = t.font.fontWithSize(17)
d.grid.rows = 1 d.grid.rows = 1
d.font = d.font.fontWithSize(12) d.font = d.font.fontWithSize(12)
t.font = t.font.fontWithSize(17)
item.titleView!.addSubview(d) item.titleView!.addSubview(d)
item.titleView!.grid.views?.append(d) item.titleView!.grid.views?.append(d)
item.titleView!.grid.axis.rows = 2 item.titleView!.grid.axis.rows = 2
...@@ -419,9 +297,12 @@ public class NavigationBar : UINavigationBar { ...@@ -419,9 +297,12 @@ public class NavigationBar : UINavigationBar {
c.bounds.size = c is MaterialSwitch ? backButton.bounds.size : c.intrinsicContentSize() c.bounds.size = c is MaterialSwitch ? backButton.bounds.size : c.intrinsicContentSize()
n.append(UIBarButtonItem(customView: c)) 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) let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = item.inset spacer.width = item.inset
n.append(spacer) n.append(spacer)
item.rightBarButtonItems = n.reverse() item.rightBarButtonItems = n.reverse()
} }
...@@ -441,23 +322,9 @@ public class NavigationBar : UINavigationBar { ...@@ -441,23 +322,9 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
prepareVisualLayer()
prepareBackButton() prepareBackButton()
} }
/// 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.cornerRadius = cornerRadius
}
/// Prepares the backButton. /// Prepares the backButton.
internal func prepareBackButton() { internal func prepareBackButton() {
backButton.pulseScale = false backButton.pulseScale = false
......
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