Commit bb852d76 by danieldahan

renamed MenuView to MenuLayout

parent fdf87ffa
...@@ -58,9 +58,9 @@ ...@@ -58,9 +58,9 @@
</Group> </Group>
<Group <Group
location = "container:" location = "container:"
name = "MenuView"> name = "MenuLayout">
<FileRef <FileRef
location = "group:Programmatic/MenuView/MenuView.xcodeproj"> location = "group:Programmatic/MenuLayout/MenuLayout.xcodeproj">
</FileRef> </FileRef>
</Group> </Group>
<Group <Group
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "self:MenuView.xcodeproj"> location = "self:MenuLayout.xcodeproj">
</FileRef> </FileRef>
</Workspace> </Workspace>
...@@ -59,6 +59,7 @@ class ViewController: UIViewController { ...@@ -59,6 +59,7 @@ class ViewController: UIViewController {
if menuLayout.opened { if menuLayout.opened {
menuLayout.close() menuLayout.close()
} else { } else {
// (menuLayout.items?.first?.button as? MaterialButton)?.animate(MaterialAnimation.rotate(1))
menuLayout.open() { (item: MenuLayoutItem) in menuLayout.open() { (item: MenuLayoutItem) in
(item.button as? MaterialButton)?.pulse() (item.button as? MaterialButton)?.pulse()
} }
...@@ -78,36 +79,36 @@ class ViewController: UIViewController { ...@@ -78,36 +79,36 @@ class ViewController: UIViewController {
let image: UIImage? = UIImage(named: "ic_add_white") let image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton() let btn1: FabButton = FabButton()
btn1.depth = .None btn1.depth = .Depth1
btn1.setImage(image, forState: .Normal) btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted) btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: "handleOpenMenuLayout", forControlEvents: .TouchUpInside) btn1.addTarget(self, action: "handleOpenMenuLayout", forControlEvents: .TouchUpInside)
view.addSubview(btn1) view.addSubview(btn1)
let btn2: FabButton = FabButton() let btn2: FabButton = FabButton()
btn2.depth = .None btn2.depth = .Depth1
btn2.backgroundColor = MaterialColor.blue.base btn2.backgroundColor = MaterialColor.blue.base
btn2.setImage(image, forState: .Normal) btn2.setImage(image, forState: .Normal)
btn2.setImage(image, forState: .Highlighted) btn2.setImage(image, forState: .Highlighted)
view.addSubview(btn2) view.addSubview(btn2)
let btn3: FabButton = FabButton() let btn3: FabButton = FabButton()
btn3.depth = .None btn3.depth = .Depth1
btn3.backgroundColor = MaterialColor.green.base btn3.backgroundColor = MaterialColor.green.base
btn3.setImage(image, forState: .Normal) btn3.setImage(image, forState: .Normal)
btn3.setImage(image, forState: .Highlighted) btn3.setImage(image, forState: .Highlighted)
view.addSubview(btn3) view.addSubview(btn3)
let btn4: FabButton = FabButton() let btn4: FabButton = FabButton()
btn4.depth = .None btn4.depth = .Depth1
btn4.backgroundColor = MaterialColor.yellow.base btn4.backgroundColor = MaterialColor.yellow.base
btn4.setImage(image, forState: .Normal) btn4.setImage(image, forState: .Normal)
btn4.setImage(image, forState: .Highlighted) btn4.setImage(image, forState: .Highlighted)
view.addSubview(btn4) view.addSubview(btn4)
menuLayout = MenuLayout() menuLayout = MenuLayout()
menuLayout.baseSize = CGSizeMake(48, 48) menuLayout.baseSize = CGSizeMake(56, 56)
menuLayout.itemSize = CGSizeMake(36, 36) menuLayout.itemSize = CGSizeMake(48, 48)
menuLayout.items = [ menuLayout.items = [
MenuLayoutItem(button: btn1), MenuLayoutItem(button: btn1),
......
...@@ -391,9 +391,9 @@ ...@@ -391,9 +391,9 @@
96D88C541C132A7700B91418 /* Navigation */ = { 96D88C541C132A7700B91418 /* Navigation */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
65FDC2EA1C66858A00103AC2 /* MenuLayout.swift */,
96D88C151C1328D800B91418 /* NavigationBarView.swift */, 96D88C151C1328D800B91418 /* NavigationBarView.swift */,
96D88C1D1C1328D800B91418 /* SideNavigationViewController.swift */, 96D88C1D1C1328D800B91418 /* SideNavigationViewController.swift */,
65FDC2EA1C66858A00103AC2 /* MenuLayout.swift */,
); );
name = Navigation; name = Navigation;
sourceTree = "<group>"; sourceTree = "<group>";
......
...@@ -407,7 +407,7 @@ public class CardView : MaterialPulseView { ...@@ -407,7 +407,7 @@ public class CardView : MaterialPulseView {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
pulseColor = MaterialColor.blueGrey.lighten4 pulseColor = MaterialColor.blueGrey.lighten4
depth = .Depth2 depth = .Depth1
dividerColor = MaterialColor.blueGrey.lighten5 dividerColor = MaterialColor.blueGrey.lighten5
} }
......
...@@ -41,7 +41,7 @@ public class FabButton : MaterialButton { ...@@ -41,7 +41,7 @@ public class FabButton : MaterialButton {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
backgroundColor = MaterialColor.red.darken1 backgroundColor = MaterialColor.red.darken1
depth = .Depth2 depth = .Depth1
shape = .Circle shape = .Circle
} }
} }
\ No newline at end of file
...@@ -544,7 +544,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -544,7 +544,7 @@ public class ImageCardView : MaterialPulseView {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
pulseColor = MaterialColor.blueGrey.lighten4 pulseColor = MaterialColor.blueGrey.lighten4
depth = .Depth2 depth = .Depth1
dividerColor = MaterialColor.blueGrey.lighten5 dividerColor = MaterialColor.blueGrey.lighten5
} }
......
...@@ -64,6 +64,9 @@ public class MenuLayout { ...@@ -64,6 +64,9 @@ public class MenuLayout {
/// A Boolean that indicates if the menu is open or not. /// A Boolean that indicates if the menu is open or not.
public private(set) var opened: Bool = false public private(set) var opened: Bool = false
/// Animation duration.
public var duration: Double = 0.07
/// The position of the menu. /// The position of the menu.
public var position: MenuLayoutPosition = .BottomRight { public var position: MenuLayoutPosition = .BottomRight {
didSet { didSet {
...@@ -90,6 +93,7 @@ public class MenuLayout { ...@@ -90,6 +93,7 @@ public class MenuLayout {
} }
public func reloadLayout() { public func reloadLayout() {
opened = false
switch position { switch position {
case .TopLeft: case .TopLeft:
layoutTopLeft() layoutTopLeft()
...@@ -137,7 +141,7 @@ public class MenuLayout { ...@@ -137,7 +141,7 @@ public class MenuLayout {
} }
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
item.button.hidden = false item.button.hidden = false
UIView.animateWithDuration(Double(i) * 0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 1 item.button.alpha = 1
item.button.frame.origin.y = base!.button.frame.origin.y - CGFloat(i) * self.itemSize.height - CGFloat(i) * 16 item.button.frame.origin.y = base!.button.frame.origin.y - CGFloat(i) * self.itemSize.height - CGFloat(i) * 16
...@@ -154,7 +158,7 @@ public class MenuLayout { ...@@ -154,7 +158,7 @@ public class MenuLayout {
if let v: Array<MenuLayoutItem> = items { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
UIView.animateWithDuration(0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 0 item.button.alpha = 0
item.button.frame.origin.y = self.height - item.button.bounds.height - 16 item.button.frame.origin.y = self.height - item.button.bounds.height - 16
...@@ -177,7 +181,7 @@ public class MenuLayout { ...@@ -177,7 +181,7 @@ public class MenuLayout {
} }
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
item.button.hidden = false item.button.hidden = false
UIView.animateWithDuration(Double(i) * 0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 1 item.button.alpha = 1
item.button.frame.origin.y = base!.button.frame.origin.y + self.baseSize.height + CGFloat(i - 1) * self.itemSize.height + CGFloat(i) * 16 item.button.frame.origin.y = base!.button.frame.origin.y + self.baseSize.height + CGFloat(i - 1) * self.itemSize.height + CGFloat(i) * 16
...@@ -194,7 +198,7 @@ public class MenuLayout { ...@@ -194,7 +198,7 @@ public class MenuLayout {
if let v: Array<MenuLayoutItem> = items { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
UIView.animateWithDuration(0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { animations: {
item.button.alpha = 0 item.button.alpha = 0
item.button.frame.origin.y = 16 item.button.frame.origin.y = 16
...@@ -217,7 +221,7 @@ public class MenuLayout { ...@@ -217,7 +221,7 @@ public class MenuLayout {
} }
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
item.button.hidden = false item.button.hidden = false
UIView.animateWithDuration(Double(i) * 0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 1 item.button.alpha = 1
item.button.frame.origin.x = base!.button.frame.origin.x - CGFloat(i) * self.itemSize.width - CGFloat(i) * 16 item.button.frame.origin.x = base!.button.frame.origin.x - CGFloat(i) * self.itemSize.width - CGFloat(i) * 16
...@@ -234,7 +238,7 @@ public class MenuLayout { ...@@ -234,7 +238,7 @@ public class MenuLayout {
if let v: Array<MenuLayoutItem> = items { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
UIView.animateWithDuration(0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 0 item.button.alpha = 0
item.button.frame.origin.x = self.width - item.button.bounds.width - 16 item.button.frame.origin.x = self.width - item.button.bounds.width - 16
...@@ -257,7 +261,7 @@ public class MenuLayout { ...@@ -257,7 +261,7 @@ public class MenuLayout {
} }
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
item.button.hidden = false item.button.hidden = false
UIView.animateWithDuration(Double(i) * 0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { [unowned self] in animations: { [unowned self] in
item.button.alpha = 1 item.button.alpha = 1
item.button.frame.origin.x = base!.button.frame.origin.x + self.baseSize.width + CGFloat(i - 1) * self.itemSize.width + CGFloat(i) * 16 item.button.frame.origin.x = base!.button.frame.origin.x + self.baseSize.width + CGFloat(i - 1) * self.itemSize.width + CGFloat(i) * 16
...@@ -274,7 +278,7 @@ public class MenuLayout { ...@@ -274,7 +278,7 @@ public class MenuLayout {
if let v: Array<MenuLayoutItem> = items { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
UIView.animateWithDuration(0.15, UIView.animateWithDuration(Double(i) * duration,
animations: { animations: {
item.button.alpha = 0 item.button.alpha = 0
item.button.frame.origin.x = 16 item.button.frame.origin.x = 16
......
...@@ -332,7 +332,7 @@ public class NavigationBarView : MaterialView { ...@@ -332,7 +332,7 @@ public class NavigationBarView : MaterialView {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
depth = .Depth2 depth = .Depth1
} }
/** /**
......
...@@ -42,7 +42,7 @@ public class RaisedButton : MaterialButton { ...@@ -42,7 +42,7 @@ public class RaisedButton : MaterialButton {
super.prepareView() super.prepareView()
setTitleColor(MaterialColor.white, forState: .Normal) setTitleColor(MaterialColor.white, forState: .Normal)
backgroundColor = MaterialColor.blue.accent3 backgroundColor = MaterialColor.blue.accent3
depth = .Depth2 depth = .Depth1
cornerRadius = .Radius1 cornerRadius = .Radius1
contentInsetPreset = .WideRectangle3 contentInsetPreset = .WideRectangle3
} }
......
...@@ -234,7 +234,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -234,7 +234,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
A MaterialDepth property that is used to set the depth of the A MaterialDepth property that is used to set the depth of the
leftView when opened. leftView when opened.
*/ */
public var depth: MaterialDepth = .Depth2 public var depth: MaterialDepth = .Depth1
/** /**
A MaterialView property that is used to hide and reveal the A MaterialView property that is used to hide and reveal the
......
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