Commit b2580b70 by Daniel Dahan

fixed issue where rootViewController was crashing when calling the transition method

parent c87070f1
...@@ -37,27 +37,27 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe ...@@ -37,27 +37,27 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
delegate = self delegate = self
} }
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Began"); print("NavigationDrawerController - Pan Began");
} }
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Ended"); print("NavigationDrawerController - Pan Ended");
} }
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Open"); print("NavigationDrawerController - Will Open");
} }
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - DId Open"); print("NavigationDrawerController - DId Open");
} }
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Close"); print("NavigationDrawerController - Will Close");
} }
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Close"); print("NavigationDrawerController - Did Close");
} }
...@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe ...@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
print("NavigationDrawerController - Status Bar Hidden: ", hidden ? "Yes" : "No"); print("NavigationDrawerController - Status Bar Hidden: ", hidden ? "Yes" : "No");
} }
func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Tap"); print("NavigationDrawerController - Did Tap");
} }
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
// print("NavigationDrawerController - Did Change"); // print("NavigationDrawerController - Did Change");
} }
} }
...@@ -66,7 +66,7 @@ class RecipesViewController: UIViewController { ...@@ -66,7 +66,7 @@ class RecipesViewController: UIViewController {
override func viewDidAppear(animated: Bool) { override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
// Enable the SideNavigation. // Enable the NavigationDrawer.
navigationDrawerController?.enabled = true navigationDrawerController?.enabled = true
(menuController as? AppMenuController)?.showMenuView() (menuController as? AppMenuController)?.showMenuView()
} }
......
...@@ -116,7 +116,8 @@ extension AppLeftViewController: UITableViewDelegate { ...@@ -116,7 +116,8 @@ extension AppLeftViewController: UITableViewDelegate {
if let v: NavigationController = navigationDrawerController?.rootViewController as? NavigationController { if let v: NavigationController = navigationDrawerController?.rootViewController as? NavigationController {
switch item.text { switch item.text {
case "Orange": case "Orange":
v.pushViewController(OrangeViewController(), animated: true) navigationDrawerController?.transitionFromRootViewController(OrangeViewController())
// v.pushViewController(OrangeViewController(), animated: true)
case "Purple": case "Purple":
v.pushViewController(PurpleViewController(), animated: true) v.pushViewController(PurpleViewController(), animated: true)
case "Green": case "Green":
......
...@@ -37,27 +37,27 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe ...@@ -37,27 +37,27 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
delegate = self delegate = self
} }
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Began"); print("NavigationDrawerController - Pan Began");
} }
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Ended"); print("NavigationDrawerController - Pan Ended");
} }
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Open"); print("NavigationDrawerController - Will Open");
} }
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - DId Open"); print("NavigationDrawerController - DId Open");
} }
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Close"); print("NavigationDrawerController - Will Close");
} }
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) { func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Close"); print("NavigationDrawerController - Did Close");
} }
...@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe ...@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
print("NavigationDrawerController - Status Bar Hidden: ", hidden ? "Yes" : "No"); print("NavigationDrawerController - Status Bar Hidden: ", hidden ? "Yes" : "No");
} }
func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Tap"); print("NavigationDrawerController - Did Tap");
} }
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) { func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
// print("NavigationDrawerController - Did Change"); // print("NavigationDrawerController - Did Change");
} }
} }
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; }; 96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; };
96BCB7E01CB40DC500C806FE /* NavigationDrawerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; }; 96BCB7E01CB40DC500C806FE /* NavigationDrawerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; };
96BCB7E11CB40DC500C806FE /* BarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; }; 96BCB7E11CB40DC500C806FE /* BarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; };
96BCB7E21CB40DC500C806FE /* BarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* BarController.swift */; }; 96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* RootController.swift */; };
96BCB7E31CB40DC500C806FE /* TabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; }; 96BCB7E31CB40DC500C806FE /* TabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; };
96BCB7E41CB40DC500C806FE /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79B1CB40DC500C806FE /* Text.swift */; }; 96BCB7E41CB40DC500C806FE /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79B1CB40DC500C806FE /* Text.swift */; };
96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79C1CB40DC500C806FE /* TextField.swift */; }; 96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79C1CB40DC500C806FE /* TextField.swift */; };
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
96BCB83A1CB4115200C806FE /* SearchBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83A1CB4115200C806FE /* SearchBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83C1CB4115200C806FE /* BarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83D1CB4115200C806FE /* BarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* BarController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83D1CB4115200C806FE /* RootController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* RootController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78D1CB40DC500C806FE /* Menu.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83E1CB4115200C806FE /* Menu.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78D1CB40DC500C806FE /* Menu.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB8401CB4115200C806FE /* MenuController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
96BCB7961CB40DC500C806FE /* SearchBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarController.swift; sourceTree = "<group>"; }; 96BCB7961CB40DC500C806FE /* SearchBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarController.swift; sourceTree = "<group>"; };
96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationDrawerController.swift; sourceTree = "<group>"; }; 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationDrawerController.swift; sourceTree = "<group>"; };
96BCB7981CB40DC500C806FE /* BarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarView.swift; sourceTree = "<group>"; }; 96BCB7981CB40DC500C806FE /* BarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarView.swift; sourceTree = "<group>"; };
96BCB7991CB40DC500C806FE /* BarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarController.swift; sourceTree = "<group>"; }; 96BCB7991CB40DC500C806FE /* RootController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootController.swift; sourceTree = "<group>"; };
96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; }; 96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; };
96BCB79B1CB40DC500C806FE /* Text.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Text.swift; sourceTree = "<group>"; }; 96BCB79B1CB40DC500C806FE /* Text.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Text.swift; sourceTree = "<group>"; };
96BCB79C1CB40DC500C806FE /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; }; 96BCB79C1CB40DC500C806FE /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
...@@ -445,9 +445,9 @@ ...@@ -445,9 +445,9 @@
96BCB8011CB40F1700C806FE /* Navigation */ = { 96BCB8011CB40F1700C806FE /* Navigation */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB7991CB40DC500C806FE /* RootController.swift */,
96BCB75E1CB40DC500C806FE /* ControlView.swift */, 96BCB75E1CB40DC500C806FE /* ControlView.swift */,
96BCB7981CB40DC500C806FE /* BarView.swift */, 96BCB7981CB40DC500C806FE /* BarView.swift */,
96BCB7991CB40DC500C806FE /* BarController.swift */,
96BCB7951CB40DC500C806FE /* SearchBar.swift */, 96BCB7951CB40DC500C806FE /* SearchBar.swift */,
96BCB7961CB40DC500C806FE /* SearchBarController.swift */, 96BCB7961CB40DC500C806FE /* SearchBarController.swift */,
96BCB79F1CB40DC500C806FE /* Toolbar.swift */, 96BCB79F1CB40DC500C806FE /* Toolbar.swift */,
...@@ -687,7 +687,7 @@ ...@@ -687,7 +687,7 @@
96BCB83A1CB4115200C806FE /* SearchBarController.swift in Headers */, 96BCB83A1CB4115200C806FE /* SearchBarController.swift in Headers */,
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */, 96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */,
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */, 96BCB83C1CB4115200C806FE /* BarView.swift in Headers */,
96BCB83D1CB4115200C806FE /* BarController.swift in Headers */, 96BCB83D1CB4115200C806FE /* RootController.swift in Headers */,
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */, 96BCB83E1CB4115200C806FE /* Menu.swift in Headers */,
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */, 96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */,
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */, 96BCB8401CB4115200C806FE /* MenuController.swift in Headers */,
...@@ -945,7 +945,7 @@ ...@@ -945,7 +945,7 @@
96BCB7B81CB40DC500C806FE /* MaterialBorder.swift in Sources */, 96BCB7B81CB40DC500C806FE /* MaterialBorder.swift in Sources */,
96BCB7A61CB40DC500C806FE /* CardView.swift in Sources */, 96BCB7A61CB40DC500C806FE /* CardView.swift in Sources */,
96BCB7C91CB40DC500C806FE /* MaterialLayer.swift in Sources */, 96BCB7C91CB40DC500C806FE /* MaterialLayer.swift in Sources */,
96BCB7E21CB40DC500C806FE /* BarController.swift in Sources */, 96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */,
96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */, 96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */,
96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */, 96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */,
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */, 96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */,
......
...@@ -49,104 +49,11 @@ public extension UIViewController { ...@@ -49,104 +49,11 @@ public extension UIViewController {
} }
@IBDesignable @IBDesignable
public class MenuController : UIViewController { public class MenuController : RootController {
/// Reference to the MenuView. /// Reference to the MenuView.
public private(set) lazy var menuView: MenuView = MenuView() public private(set) lazy var menuView: MenuView = MenuView()
/** /**
A Boolean property used to enable and disable interactivity
with the rootViewController.
*/
@IBInspectable public var userInteractionEnabled: Bool {
get {
return rootViewController.view.userInteractionEnabled
}
set(value) {
rootViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the rootViewController, it
is recommended to use the transitionFromRootViewController
helper method.
*/
public private(set) var rootViewController: UIViewController!
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
An initializer that initializes the object with an Optional nib and bundle.
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
}
/**
An initializer for the BarController.
- Parameter rootViewController: The main UIViewController.
*/
public init(rootViewController: UIViewController) {
super.init(nibName: nil, bundle: nil)
self.rootViewController = rootViewController
prepareView()
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/**
A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap
with the active rootViewController.
- Parameter duration: A NSTimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active rootViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active rootViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active rootViewController
to the toViewController has completed.
*/
public func transitionFromRootViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController)
toViewController.view.frame = rootViewController.view.frame
transitionFromViewController(rootViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [weak self] (result: Bool) in
if let s: MenuController = self {
toViewController.didMoveToParentViewController(s)
s.rootViewController.removeFromParentViewController()
s.rootViewController = toViewController
s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result)
}
})
}
/**
Opens the menu with a callback. Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when - Parameter completion: An Optional callback that is executed when
all menu items have been opened. all menu items have been opened.
...@@ -175,17 +82,25 @@ public class MenuController : UIViewController { ...@@ -175,17 +82,25 @@ public class MenuController : UIViewController {
} }
/** /**
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
public override func layoutSubviews() {
super.layoutSubviews()
rootViewController.view.frame = view.bounds
}
/**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
public func prepareView() { public override func prepareView() {
view.clipsToBounds = true super.prepareView()
view.contentScaleFactor = MaterialDevice.scale
prepareMenuView() prepareMenuView()
prepareRootViewController()
} }
/// Prepares the MenuView. /// Prepares the MenuView.
...@@ -193,33 +108,4 @@ public class MenuController : UIViewController { ...@@ -193,33 +108,4 @@ public class MenuController : UIViewController {
menuView.zPosition = 1000 menuView.zPosition = 1000
view.addSubview(menuView) view.addSubview(menuView)
} }
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view)
}
/**
A method that adds the passed in controller as a child of
the MenuController within the passed in
container view.
- Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
}
}
/// Layout subviews.
private func layoutSubviews() {
rootViewController.view.frame = view.bounds
}
} }
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import UIKit import UIKit
@IBDesignable @IBDesignable
public class BarController : UIViewController { public class RootController : UIViewController {
/// Device status bar style. /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle { public var statusBarStyle: UIStatusBarStyle {
get { get {
...@@ -92,6 +92,11 @@ public class BarController : UIViewController { ...@@ -92,6 +92,11 @@ public class BarController : UIViewController {
prepareView() prepareView()
} }
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/** /**
A method to swap rootViewController objects. A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap - Parameter toViewController: The UIViewController to swap
...@@ -118,19 +123,25 @@ public class BarController : UIViewController { ...@@ -118,19 +123,25 @@ public class BarController : UIViewController {
options: options, options: options,
animations: animations, animations: animations,
completion: { [weak self] (result: Bool) in completion: { [weak self] (result: Bool) in
if let s: BarController = self { if let s: RootController = self {
toViewController.didMoveToParentViewController(s) toViewController.didMoveToParentViewController(s)
s.rootViewController.removeFromParentViewController() s.rootViewController.removeFromParentViewController()
s.rootViewController = toViewController s.rootViewController = toViewController
s.rootViewController.view.clipsToBounds = true s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result) completion?(result)
} }
}) })
} }
/** /**
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
public func layoutSubviews() {}
/**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
to initialize property values and other setup operations. to initialize property values and other setup operations.
...@@ -144,7 +155,7 @@ public class BarController : UIViewController { ...@@ -144,7 +155,7 @@ public class BarController : UIViewController {
} }
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
private func prepareRootViewController() { internal func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view) prepareViewControllerWithinContainer(rootViewController, container: view)
} }
...@@ -156,14 +167,15 @@ public class BarController : UIViewController { ...@@ -156,14 +167,15 @@ public class BarController : UIViewController {
- Parameter container: A UIView that is the parent of the - Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy. passed in controller view within the view hierarchy.
*/ */
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) { internal func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController { if let v: UIViewController = viewController {
addChildViewController(v) addChildViewController(v)
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self) v.didMoveToParentViewController(self)
v.view.clipsToBounds = true v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view) v.view.contentScaleFactor = MaterialDevice.scale
container.sendSubviewToBack(v.view)
} }
} }
} }
...@@ -48,17 +48,17 @@ public extension UIViewController { ...@@ -48,17 +48,17 @@ public extension UIViewController {
} }
} }
public class SearchBarController : BarController { public class SearchBarController : RootController {
/// Reference to the SearchBar. /// Reference to the SearchBar.
public private(set) var searchBar: SearchBar! public private(set) var searchBar: SearchBar!
public override func viewWillLayoutSubviews() { /**
super.viewWillLayoutSubviews() To execute in the order of the layout chain, override this
layoutSubviews() method. LayoutSubviews should be called immediately, unless you
} have a certain need.
*/
/// Layout subviews. public override func layoutSubviews() {
public func layoutSubviews() { super.layoutSubviews()
if let v: SearchBar = searchBar { if let v: SearchBar = searchBar {
v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20 v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20
......
...@@ -49,111 +49,19 @@ public extension UIViewController { ...@@ -49,111 +49,19 @@ public extension UIViewController {
} }
@IBDesignable @IBDesignable
public class StatusBarController : UIViewController { public class StatusBarController : RootController {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// A reference to the statusBarView. /// A reference to the statusBarView.
public private(set) var statusBarView: MaterialView! public private(set) var statusBarView: MaterialView!
/** /**
A Boolean property used to enable and disable interactivity To execute in the order of the layout chain, override this
with the rootViewController. method. LayoutSubviews should be called immediately, unless you
*/ have a certain need.
@IBInspectable public var userInteractionEnabled: Bool {
get {
return rootViewController.view.userInteractionEnabled
}
set(value) {
rootViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the rootViewController, it
is recommended to use the transitionFromRootViewController
helper method.
*/
public private(set) var rootViewController: UIViewController!
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
An initializer that initializes the object with an Optional nib and bundle.
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
}
/**
An initializer for the BarController.
- Parameter rootViewController: The main UIViewController.
*/
public init(rootViewController: UIViewController) {
super.init(nibName: nil, bundle: nil)
self.rootViewController = rootViewController
prepareView()
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/**
A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap
with the active rootViewController.
- Parameter duration: A NSTimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active rootViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active rootViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active rootViewController
to the toViewController has completed.
*/ */
public func transitionFromRootViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { public override func layoutSubviews() {
rootViewController.willMoveToParentViewController(nil) super.layoutSubviews()
addChildViewController(toViewController) statusBarView.hidden = MaterialDevice.isLandscape && .iPhone == MaterialDevice.type
toViewController.view.frame = rootViewController.view.frame rootViewController.view.frame = view.bounds
transitionFromViewController(rootViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [weak self] (result: Bool) in
if let s: StatusBarController = self {
toViewController.didMoveToParentViewController(s)
s.rootViewController.removeFromParentViewController()
s.rootViewController = toViewController
s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result)
}
})
} }
/** /**
...@@ -163,11 +71,9 @@ public class StatusBarController : UIViewController { ...@@ -163,11 +71,9 @@ public class StatusBarController : UIViewController {
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
public func prepareView() { public override func prepareView() {
view.clipsToBounds = true super.prepareView()
view.contentScaleFactor = MaterialDevice.scale
prepareStatusBarView() prepareStatusBarView()
prepareRootViewController()
} }
/// Prepares the statusBarView. /// Prepares the statusBarView.
...@@ -177,34 +83,4 @@ public class StatusBarController : UIViewController { ...@@ -177,34 +83,4 @@ public class StatusBarController : UIViewController {
statusBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.12) statusBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.12)
view.layout(statusBarView).top(0).horizontally().height(20) view.layout(statusBarView).top(0).horizontally().height(20)
} }
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view)
}
/**
A method that adds the passed in controller as a child of
the StatusBarController within the passed in
container view.
- Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
}
}
/// Layout subviews.
private func layoutSubviews() {
statusBarView.hidden = MaterialDevice.isLandscape && .iPhone == MaterialDevice.type
rootViewController.view.frame = view.bounds
}
} }
...@@ -64,7 +64,7 @@ public protocol ToolbarControllerDelegate : MaterialDelegate { ...@@ -64,7 +64,7 @@ public protocol ToolbarControllerDelegate : MaterialDelegate {
} }
@objc(ToolbarController) @objc(ToolbarController)
public class ToolbarController : BarController { public class ToolbarController : RootController {
/// Internal reference to the floatingViewController. /// Internal reference to the floatingViewController.
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
...@@ -151,13 +151,13 @@ public class ToolbarController : BarController { ...@@ -151,13 +151,13 @@ public class ToolbarController : BarController {
} }
} }
public override func viewWillLayoutSubviews() { /**
super.viewWillLayoutSubviews() To execute in the order of the layout chain, override this
layoutSubviews() method. LayoutSubviews should be called immediately, unless you
} have a certain need.
*/
/// Layout subviews. public override func layoutSubviews() {
public func layoutSubviews() { super.layoutSubviews()
if let v: Toolbar = toolbar { if let v: Toolbar = toolbar {
v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20 v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20
......
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