Commit 3f51240e by Daniel Dahan

updated App example

parent dfd7d96e
...@@ -52,59 +52,71 @@ class AppMenuViewController: MenuViewController { ...@@ -52,59 +52,71 @@ class AppMenuViewController: MenuViewController {
/** /**
*/ */
func handleBtn2() { func handleBtn2() {
if navigationBarViewController?.mainViewController is BlueViewController { if menuViewController?.mainViewController is BlueViewController {
return return
} }
handleMenu()
menuViewController?.transitionFromMainViewController(BlueViewController()) closeMenu { [weak self] in
navigationBarViewController?.navigationBarView.titleLabel?.text = "Blue" self?.menuViewController?.transitionFromMainViewController(BlueViewController(), options: [.TransitionCrossDissolve])
}
} }
/** /**
*/ */
func handleBtn3() { func handleBtn3() {
if navigationBarViewController?.mainViewController is GreenViewController { if menuViewController?.mainViewController is GreenViewController {
return return
} }
handleMenu() closeMenu { [weak self] in
menuViewController?.transitionFromMainViewController(GreenViewController()) self?.menuViewController?.transitionFromMainViewController(GreenViewController(), options: [.TransitionCrossDissolve])
navigationBarViewController?.navigationBarView.titleLabel?.text = "Green" }
} }
/** /**
*/ */
func handleBtn4() { func handleBtn4() {
if navigationBarViewController?.mainViewController is FeedViewController { if (menuViewController?.mainViewController as? NavigationBarViewController)?.mainViewController is FeedViewController {
return return
} }
handleMenu() closeMenu { [weak self] in
menuViewController?.transitionFromMainViewController(AppNavigationBarViewController(mainViewController: FeedViewController())) self?.menuViewController?.transitionFromMainViewController(AppNavigationBarViewController(mainViewController: FeedViewController()), options: [.TransitionCrossDissolve])
navigationBarViewController?.navigationBarView.titleLabel?.text = "Feed" }
}
/// Opens the menu with a callback.
func openMenu(completion: (() -> Void)? = nil) {
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(0.125))
menuView.menu.open { [weak self] (v: UIView) in
(v as? MaterialButton)?.pulse()
if self?.menuView.menu.views?.last == v {
completion?()
}
}
}
/// Closes the menu with a callback.
func closeMenu(completion: (() -> Void)? = nil) {
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(-0.125))
menuView.close(completion)
} }
/// Handle the menuView touch event. /// Handle the menuView touch event.
func handleMenu() { func handleMenu() {
var rotate: Double = -0.125
if true == menuView.menu.opened { if true == menuView.menu.opened {
hideMenuBackdrop() hideMenuBackdrop()
menuView.menu.close() closeMenu()
} else { } else {
showMenuBackdrop() showMenuBackdrop()
rotate = 0.125 openMenu()
menuView.menu.open() { (v: UIView) in
(v as? MaterialButton)?.pulse()
}
} }
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(rotate))
} }
/// Prepares view. /// Prepares view.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.black
} }
/// Prepares the add button. /// Prepares the add button.
...@@ -141,7 +153,6 @@ class AppMenuViewController: MenuViewController { ...@@ -141,7 +153,6 @@ class AppMenuViewController: MenuViewController {
btn4.addTarget(self, action: "handleBtn4", forControlEvents: .TouchUpInside) btn4.addTarget(self, action: "handleBtn4", forControlEvents: .TouchUpInside)
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
menuView.menu.direction = .Up
menuView.menu.baseViewSize = baseViewSize menuView.menu.baseViewSize = baseViewSize
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
......
...@@ -81,6 +81,7 @@ class AppNavigationBarViewController: NavigationBarViewController { ...@@ -81,6 +81,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
guard let v: AppSearchBarViewController = AppSearchBarViewController(mainViewController: SearchListViewController()) else { guard let v: AppSearchBarViewController = AppSearchBarViewController(mainViewController: SearchListViewController()) else {
return return
} }
navigationBarViewController?.floatingViewController = v navigationBarViewController?.floatingViewController = v
} }
......
...@@ -73,9 +73,9 @@ public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimati ...@@ -73,9 +73,9 @@ public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimati
case .Left: case .Left:
return kCATransitionFromLeft return kCATransitionFromLeft
case .Top: case .Top:
return kCATransitionFromTop
case .Bottom:
return kCATransitionFromBottom return kCATransitionFromBottom
case .Bottom:
return kCATransitionFromTop
} }
} }
......
...@@ -48,6 +48,24 @@ public class MenuView : MaterialPulseView { ...@@ -48,6 +48,24 @@ public class MenuView : MaterialPulseView {
clipsToBounds = false clipsToBounds = false
backgroundColor = nil backgroundColor = nil
} }
/// Opens the menu with a callback.
public func open(completion: (() -> Void)? = nil) {
menu.open { [weak self] (v: UIView) in
if self?.menu.views?.last == v {
completion?()
}
}
}
/// Closes the menu with a callback.
public func close(completion: (() -> Void)? = nil) {
menu.close { [weak self] (v: UIView) in
if self?.menu.views?.last == v {
completion?()
}
}
}
public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? { public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
/** /**
......
...@@ -49,18 +49,32 @@ public extension UIViewController { ...@@ -49,18 +49,32 @@ public extension UIViewController {
} }
public class NavigationBarViewController: UIViewController { public class NavigationBarViewController: UIViewController {
/// Reference to the NavigationBarView.
public private(set) lazy var navigationBarView: NavigationBarView = NavigationBarView()
/// Internal reference to the floatingViewController. /// Internal reference to the floatingViewController.
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
/// Reference to the NavigationBarView.
public private(set) lazy var navigationBarView: NavigationBarView = NavigationBarView()
/// A floating UIViewController. /// A floating UIViewController.
public var floatingViewController: UIViewController? { public var floatingViewController: UIViewController? {
get { get {
return internalFloatingViewController return internalFloatingViewController
} }
set(value) { set(value) {
if let v: UIViewController = internalFloatingViewController {
sideNavigationViewController?.enabled = true
UIView.animateWithDuration(0.5,
animations: { [unowned self] in
v.view.center.y = 2 * self.view.bounds.height
}) { [unowned self] _ in
v.willMoveToParentViewController(nil)
v.view.removeFromSuperview()
v.removeFromParentViewController()
self.internalFloatingViewController = nil
}
}
if let v: UIViewController = value { if let v: UIViewController = value {
/** /**
Disable the sideNavigationViewController from opening while in Disable the sideNavigationViewController from opening while in
...@@ -79,24 +93,11 @@ public class NavigationBarViewController: UIViewController { ...@@ -79,24 +93,11 @@ public class NavigationBarViewController: UIViewController {
// Animate the noteButton out and the noteViewController! in. // Animate the noteButton out and the noteViewController! in.
v.view.hidden = false v.view.hidden = false
internalFloatingViewController = v
UIView.animateWithDuration(0.5, UIView.animateWithDuration(0.5,
animations: { [unowned self] in animations: { [unowned self] in
v.view.center.y = self.view.bounds.height / 2 v.view.center.y = self.view.bounds.height / 2
}) }) { [unowned self] _ in
} else if let v: UIViewController = internalFloatingViewController { self.internalFloatingViewController = v
sideNavigationViewController?.enabled = true
internalFloatingViewController = nil
UIView.animateWithDuration(0.5,
animations: { [unowned self] in
v.view.center.y = 2 * self.view.bounds.height
}) { _ in
v.willMoveToParentViewController(nil)
v.view.removeFromSuperview()
v.removeFromParentViewController()
} }
} }
} }
......
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