Commit 297dc4db by Daniel Dahan

preparation for Menu component

parent 10002a2c
{
"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_create_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_create_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_create_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_note_add_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_note_add_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_note_add_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -29,40 +29,56 @@
*/
/**
This is an example of using the Menu component. It is designed to take any array
of buttons and provide a facility to animate them opened and closed as a group.
*/
import UIKit
import Material
class ViewController: UIViewController {
/// Menu component.
private var menu: Menu!
/// Default spacing size
let spacing: CGFloat = 16
/// Base button diameter, otherwise default to buttonSize (48 x 48)
let diameter: CGFloat = 56
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareMenuExample()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
}
/// Handle orientation.
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
// menuLayout.origin.x = size.width
// menuLayout.origin.y = size.height
menu.reloadLayout()
// Handle orientation change.
menu.origin = CGPointMake(view.bounds.height - diameter - spacing, view.bounds.width - diameter - spacing)
}
/// Handle the base button touch event.
internal func handleOpenMenu() {
if menu.opened {
menu.close()
} else {
// (menuLayout.items?.first?.button as? MaterialButton)?.animate(MaterialAnimation.rotate(1))
menu.open() { (button: UIButton) in
(button as? MaterialButton)?.pulse()
// Only trigger open and close animations when enabled.
if menu.enabled {
let image: UIImage?
if menu.opened {
menu.close()
image = UIImage(named: "ic_add_white")
} else {
menu.open() { (button: UIButton) in
(button as? MaterialButton)?.pulse()
}
image = UIImage(named: "ic_close_white")
}
// Add a nice rotation animation to the base button.
(menu.buttons?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(1))
menu.buttons?.first?.setImage(image, forState: .Normal)
menu.buttons?.first?.setImage(image, forState: .Highlighted)
}
}
......@@ -73,38 +89,43 @@ class ViewController: UIViewController {
/// Prepares the Menu example.
private func prepareMenuExample() {
let image: UIImage? = UIImage(named: "ic_add_white")
var image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton()
btn1.depth = .Depth1
/**
Remove the pulse animation, so the rotation animation
doesn't seem like too much with the pulse animation.
*/
btn1.pulseColor = nil
btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: "handleOpenMenu", forControlEvents: .TouchUpInside)
view.addSubview(btn1)
image = UIImage(named: "ic_create_white")
let btn2: FabButton = FabButton()
btn2.depth = .Depth1
btn2.backgroundColor = MaterialColor.blue.base
btn2.setImage(image, forState: .Normal)
btn2.setImage(image, forState: .Highlighted)
view.addSubview(btn2)
image = UIImage(named: "ic_photo_camera_white")
let btn3: FabButton = FabButton()
btn3.depth = .Depth1
btn3.backgroundColor = MaterialColor.green.base
btn3.setImage(image, forState: .Normal)
btn3.setImage(image, forState: .Highlighted)
view.addSubview(btn3)
image = UIImage(named: "ic_note_add_white")
let btn4: FabButton = FabButton()
btn4.depth = .Depth1
btn4.backgroundColor = MaterialColor.yellow.base
btn4.backgroundColor = MaterialColor.amber.base
btn4.setImage(image, forState: .Normal)
btn4.setImage(image, forState: .Highlighted)
view.addSubview(btn4)
menu = Menu(origin: CGPointMake(100, 100))
menu.direction = .Down
menu.baseSize = CGSizeMake(88, 88)
// Initialize the menu and setup the configuration options.
menu = Menu(origin: CGPointMake(view.bounds.width - diameter - spacing, view.bounds.height - diameter - spacing))
menu.direction = .Up
menu.baseSize = CGSizeMake(diameter, diameter)
menu.buttons = [btn1, btn2, btn3, btn4]
}
}
......
......@@ -57,6 +57,7 @@ Material is a growing project and will encounter changes throughout its developm
* [FlatButton](#flatbutton)
* [RaisedButton](#raisedbutton)
* [FabButton](#fabbutton)
* [Menu](#menu)
* [NavigationBarView](#navigationbarview)
* [SideNavigationViewController](#sidenavigationviewcontroller)
* [CardView](#cardview)
......@@ -75,6 +76,7 @@ Material is a growing project and will encounter changes throughout its developm
* ProgressBar (circular and horizontal)
* DatePicker
* TimePicker
* Switch Control
* More Examples
<a name="materialcolor"></a>
......@@ -159,7 +161,14 @@ A FabButton is essential to Material Design's overall look. Below showcases its
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialFabButton.gif)
[Learn More About FabButton](https://github.com/CosmicMind/Material/wiki/FabButton)
<a name="menu"></a>
## Menu
A Menu manages a group of UIButtons that may be animated open in the Up, Down, Left, and Right directions. The animations are fully customizable.
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialMenu.gif)
[Learn More About Menu](https://github.com/CosmicMind/Material/wiki/Menu)
<a name="navigationbarview"></a>
## NavigationBarView
......
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