Commit fdf87ffa by danieldahan

added orientation change in example

parent bfa2cd30
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
......
...@@ -36,7 +36,7 @@ import UIKit ...@@ -36,7 +36,7 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
private var menuView: MenuLayout! private var menuLayout: MenuLayout!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -44,11 +44,22 @@ class ViewController: UIViewController { ...@@ -44,11 +44,22 @@ class ViewController: UIViewController {
prepareMenuLayoutExample() prepareMenuLayoutExample()
} }
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
menuLayout.width = size.width
menuLayout.height = size.height
menuLayout.reloadLayout()
}
internal func handleOpenMenuLayout() { internal func handleOpenMenuLayout() {
if menuView.opened { if menuLayout.opened {
menuView.close() menuLayout.close()
} else { } else {
menuView.open() { (item: MenuLayoutItem) in menuLayout.open() { (item: MenuLayoutItem) in
(item.button as? MaterialButton)?.pulse() (item.button as? MaterialButton)?.pulse()
} }
} }
...@@ -63,7 +74,7 @@ class ViewController: UIViewController { ...@@ -63,7 +74,7 @@ class ViewController: UIViewController {
private func prepareMenuLayoutExample() { private func prepareMenuLayoutExample() {
let btn: FlatButton = FlatButton(frame: CGRectMake(100, 100, 100, 100)) let btn: FlatButton = FlatButton(frame: CGRectMake(100, 100, 100, 100))
btn.backgroundColor = MaterialColor.red.base btn.backgroundColor = MaterialColor.red.base
view.addSubview(btn)
let image: UIImage? = UIImage(named: "ic_add_white") let image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton() let btn1: FabButton = FabButton()
...@@ -94,15 +105,11 @@ class ViewController: UIViewController { ...@@ -94,15 +105,11 @@ class ViewController: UIViewController {
btn4.setImage(image, forState: .Highlighted) btn4.setImage(image, forState: .Highlighted)
view.addSubview(btn4) view.addSubview(btn4)
menuView = MenuLayout() menuLayout = MenuLayout()
menuView.menuPosition = .TopRight menuLayout.baseSize = CGSizeMake(48, 48)
menuView.menuDirection = .Left menuLayout.itemSize = CGSizeMake(36, 36)
menuView.baseSize = CGSizeMake(36, 36)
menuView.itemSize = CGSizeMake(36, 36)
view.addSubview(btn)
menuView.menuItems = [ menuLayout.items = [
MenuLayoutItem(button: btn1), MenuLayoutItem(button: btn1),
MenuLayoutItem(button: btn2), MenuLayoutItem(button: btn2),
MenuLayoutItem(button: btn3), MenuLayoutItem(button: btn3),
......
...@@ -65,19 +65,19 @@ public class MenuLayout { ...@@ -65,19 +65,19 @@ public class MenuLayout {
public private(set) var opened: Bool = false public private(set) var opened: Bool = false
/// The position of the menu. /// The position of the menu.
public var menuPosition: MenuLayoutPosition = .BottomRight { public var position: MenuLayoutPosition = .BottomRight {
didSet { didSet {
reloadView() reloadLayout()
} }
} }
/// The direction in which the animation opens the menu. /// The direction in which the animation opens the menu.
public var menuDirection: MenuLayoutDirection = .Up public var direction: MenuLayoutDirection = .Up
/// An Array of MenuLayoutItems. /// An Array of MenuLayoutItems.
public var menuItems: Array<MenuLayoutItem>? { public var items: Array<MenuLayoutItem>? {
didSet { didSet {
reloadView() reloadLayout()
} }
} }
...@@ -89,8 +89,8 @@ public class MenuLayout { ...@@ -89,8 +89,8 @@ public class MenuLayout {
} }
public func reloadView() { public func reloadLayout() {
switch menuPosition { switch position {
case .TopLeft: case .TopLeft:
layoutTopLeft() layoutTopLeft()
case .TopRight: case .TopRight:
...@@ -103,7 +103,7 @@ public class MenuLayout { ...@@ -103,7 +103,7 @@ public class MenuLayout {
} }
public func open(completion: ((MenuLayoutItem) -> Void)? = nil) { public func open(completion: ((MenuLayoutItem) -> Void)? = nil) {
switch menuDirection { switch direction {
case .Up: case .Up:
openUpAnimation(completion) openUpAnimation(completion)
case .Down: case .Down:
...@@ -116,7 +116,7 @@ public class MenuLayout { ...@@ -116,7 +116,7 @@ public class MenuLayout {
} }
public func close(completion: ((MenuLayoutItem) -> Void)? = nil) { public func close(completion: ((MenuLayoutItem) -> Void)? = nil) {
switch menuDirection { switch direction {
case .Up: case .Up:
closeUpAnimation(completion) closeUpAnimation(completion)
case .Down: case .Down:
...@@ -129,7 +129,7 @@ public class MenuLayout { ...@@ -129,7 +129,7 @@ public class MenuLayout {
} }
private func openUpAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { private func openUpAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
var base: MenuLayoutItem? var base: MenuLayoutItem?
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
if nil == base { if nil == base {
...@@ -151,7 +151,7 @@ public class MenuLayout { ...@@ -151,7 +151,7 @@ public class MenuLayout {
} }
public func closeUpAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { public func closeUpAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { 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(0.15,
...@@ -169,7 +169,7 @@ public class MenuLayout { ...@@ -169,7 +169,7 @@ public class MenuLayout {
} }
private func openDownAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { private func openDownAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
var base: MenuLayoutItem? var base: MenuLayoutItem?
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
if nil == base { if nil == base {
...@@ -191,7 +191,7 @@ public class MenuLayout { ...@@ -191,7 +191,7 @@ public class MenuLayout {
} }
public func closeDownAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { public func closeDownAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { 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(0.15,
...@@ -209,7 +209,7 @@ public class MenuLayout { ...@@ -209,7 +209,7 @@ public class MenuLayout {
} }
private func openLeftAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { private func openLeftAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
var base: MenuLayoutItem? var base: MenuLayoutItem?
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
if nil == base { if nil == base {
...@@ -231,7 +231,7 @@ public class MenuLayout { ...@@ -231,7 +231,7 @@ public class MenuLayout {
} }
public func closeLeftAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { public func closeLeftAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { 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(0.15,
...@@ -249,7 +249,7 @@ public class MenuLayout { ...@@ -249,7 +249,7 @@ public class MenuLayout {
} }
private func openRightAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { private func openRightAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
var base: MenuLayoutItem? var base: MenuLayoutItem?
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
if nil == base { if nil == base {
...@@ -271,7 +271,7 @@ public class MenuLayout { ...@@ -271,7 +271,7 @@ public class MenuLayout {
} }
public func closeRightAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) { public func closeRightAnimation(completion: ((MenuLayoutItem) -> Void)? = nil) {
if let v: Array<MenuLayoutItem> = menuItems { 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(0.15,
...@@ -289,7 +289,7 @@ public class MenuLayout { ...@@ -289,7 +289,7 @@ public class MenuLayout {
} }
private func layoutTopLeft() { private func layoutTopLeft() {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
if 0 == i { if 0 == i {
...@@ -309,7 +309,7 @@ public class MenuLayout { ...@@ -309,7 +309,7 @@ public class MenuLayout {
} }
private func layoutTopRight() { private func layoutTopRight() {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
if 0 == i { if 0 == i {
...@@ -329,7 +329,7 @@ public class MenuLayout { ...@@ -329,7 +329,7 @@ public class MenuLayout {
} }
private func layoutBottomLeft() { private func layoutBottomLeft() {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
if 0 == i { if 0 == i {
...@@ -349,7 +349,7 @@ public class MenuLayout { ...@@ -349,7 +349,7 @@ public class MenuLayout {
} }
private func layoutBottomRight() { private func layoutBottomRight() {
if let v: Array<MenuLayoutItem> = menuItems { if let v: Array<MenuLayoutItem> = items {
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
let item: MenuLayoutItem = v[i] let item: MenuLayoutItem = v[i]
if 0 == i { if 0 == i {
......
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