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
delegate = self
}
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Began");
}
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Ended");
}
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Open");
}
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - DId Open");
}
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Close");
}
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Close");
}
......@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
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");
}
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
// print("NavigationDrawerController - Did Change");
}
}
......@@ -66,7 +66,7 @@ class RecipesViewController: UIViewController {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// Enable the SideNavigation.
// Enable the NavigationDrawer.
navigationDrawerController?.enabled = true
(menuController as? AppMenuController)?.showMenuView()
}
......
......@@ -116,7 +116,8 @@ extension AppLeftViewController: UITableViewDelegate {
if let v: NavigationController = navigationDrawerController?.rootViewController as? NavigationController {
switch item.text {
case "Orange":
v.pushViewController(OrangeViewController(), animated: true)
navigationDrawerController?.transitionFromRootViewController(OrangeViewController())
// v.pushViewController(OrangeViewController(), animated: true)
case "Purple":
v.pushViewController(PurpleViewController(), animated: true)
case "Green":
......
......@@ -37,27 +37,27 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
delegate = self
}
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Began");
}
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Pan Ended");
}
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Open");
}
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - DId Open");
}
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Will Close");
}
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition) {
func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition) {
print("NavigationDrawerController - Did Close");
}
......@@ -65,11 +65,11 @@ class AppNavigationDrawerController: NavigationDrawerController, NavigationDrawe
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");
}
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition) {
func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition) {
// print("NavigationDrawerController - Did Change");
}
}
......@@ -82,7 +82,7 @@
96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; };
96BCB7E01CB40DC500C806FE /* NavigationDrawerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.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 */; };
96BCB7E41CB40DC500C806FE /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79B1CB40DC500C806FE /* Text.swift */; };
96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79C1CB40DC500C806FE /* TextField.swift */; };
......@@ -146,7 +146,7 @@
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, ); }; };
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, ); }; };
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, ); }; };
......@@ -273,7 +273,7 @@
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>"; };
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>"; };
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>"; };
......@@ -445,9 +445,9 @@
96BCB8011CB40F1700C806FE /* Navigation */ = {
isa = PBXGroup;
children = (
96BCB7991CB40DC500C806FE /* RootController.swift */,
96BCB75E1CB40DC500C806FE /* ControlView.swift */,
96BCB7981CB40DC500C806FE /* BarView.swift */,
96BCB7991CB40DC500C806FE /* BarController.swift */,
96BCB7951CB40DC500C806FE /* SearchBar.swift */,
96BCB7961CB40DC500C806FE /* SearchBarController.swift */,
96BCB79F1CB40DC500C806FE /* Toolbar.swift */,
......@@ -687,7 +687,7 @@
96BCB83A1CB4115200C806FE /* SearchBarController.swift in Headers */,
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */,
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */,
96BCB83D1CB4115200C806FE /* BarController.swift in Headers */,
96BCB83D1CB4115200C806FE /* RootController.swift in Headers */,
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */,
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */,
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */,
......@@ -945,7 +945,7 @@
96BCB7B81CB40DC500C806FE /* MaterialBorder.swift in Sources */,
96BCB7A61CB40DC500C806FE /* CardView.swift in Sources */,
96BCB7C91CB40DC500C806FE /* MaterialLayer.swift in Sources */,
96BCB7E21CB40DC500C806FE /* BarController.swift in Sources */,
96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */,
96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */,
96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */,
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */,
......
......@@ -49,104 +49,11 @@ public extension UIViewController {
}
@IBDesignable
public class MenuController : UIViewController {
public class MenuController : RootController {
/// Reference to the 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.
- Parameter completion: An Optional callback that is executed when
all menu items have been opened.
......@@ -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,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
public override func prepareView() {
super.prepareView()
prepareMenuView()
prepareRootViewController()
}
/// Prepares the MenuView.
......@@ -193,33 +108,4 @@ public class MenuController : UIViewController {
menuView.zPosition = 1000
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 @@
import UIKit
@objc
public enum SideNavigationPosition : NSInteger {
public enum NavigationDrawerPosition : NSInteger {
case Left
case Right
}
......@@ -60,49 +60,49 @@ public protocol NavigationDrawerControllerDelegate {
An optional delegation method that is fired before the
NavigationDrawerController opens.
*/
optional func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition)
optional func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired after the
NavigationDrawerController opened.
*/
optional func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition)
optional func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired before the
NavigationDrawerController closes.
*/
optional func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition)
optional func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired after the
NavigationDrawerController closed.
*/
optional func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: SideNavigationPosition)
optional func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture begins.
*/
optional func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition)
optional func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture changes position.
*/
optional func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition)
optional func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture ends.
*/
optional func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition)
optional func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController tap gesture executes.
*/
optional func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: SideNavigationPosition)
optional func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
......@@ -113,7 +113,7 @@ public protocol NavigationDrawerControllerDelegate {
@IBDesignable
@objc(NavigationDrawerController)
public class NavigationDrawerController : UIViewController, UIGestureRecognizerDelegate {
public class NavigationDrawerController : RootController, UIGestureRecognizerDelegate {
/**
A CGFloat property that is used internally to track
the original (x) position of the container view when panning.
......@@ -173,19 +173,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
public weak var delegate: NavigationDrawerControllerDelegate?
/**
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 CGFloat property that sets the animation duration of the
leftView when closing and opening. Defaults to 0.25.
*/
......@@ -331,23 +318,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
return rightView!.x != MaterialDevice.width
}
/**
Content view controller to encompase the entire component. This is
primarily used when the StatusBar is being hidden. The alpha value of
the rootViewController decreases, and shows the StatusBar. To avoid
this, and to add a hidden transition viewController for complex
situations, the contentViewController was added.
*/
public private(set) var contentViewController: UIViewController!
/**
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!
/**
A UIViewController property that references the
active left UIViewController.
......@@ -373,26 +343,29 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
@IBInspectable public private(set) var rightViewWidth: CGFloat!
/**
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 for the NavigationDrawerController.
- Parameter rootViewController: The main UIViewController.
- Parameter leftViewController: An Optional left UIViewController.
- Parameter rightViewController: An Optional right UIViewController.
*/
public convenience init(rootViewController: UIViewController, leftViewController: UIViewController? = nil, rightViewController: UIViewController? = nil) {
self.init()
self.rootViewController = rootViewController
public init(rootViewController: UIViewController, leftViewController: UIViewController? = nil, rightViewController: UIViewController? = nil) {
super.init(rootViewController: rootViewController)
self.leftViewController = leftViewController
self.rightViewController = rightViewController
prepareView()
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/// Layout subviews.
public func layoutSubviews() {
public override func layoutSubviews() {
if opened {
hideStatusBar()
} else {
......@@ -431,44 +404,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
}
/**
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: NavigationDrawerController = 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)
}
})
}
/**
A method that is used to set the width of the leftView when
opened. This is the recommended method of setting the leftView
width.
......@@ -906,29 +841,12 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
prepareContentViewController()
prepareRootViewController()
public override func prepareView() {
super.prepareView()
prepareLeftView()
prepareRightView()
}
/// Prepares the contentViewController.
private func prepareContentViewController() {
contentViewController = UIViewController()
contentViewController.view.frame = view.bounds
contentViewController.view.backgroundColor = MaterialColor.black
prepareViewControllerWithinContainer(contentViewController, container: view)
}
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.frame = contentViewController.view.bounds
prepareViewControllerWithinContainer(rootViewController, container: contentViewController.view)
}
/// A method that prepares the leftViewController.
private func prepareLeftViewController() {
if let v: MaterialView = leftView {
......@@ -985,26 +903,6 @@ public class NavigationDrawerController : UIViewController, UIGestureRecognizerD
}
}
/**
A method that adds the passed in controller as a child of
the NavigationDrawerController 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]
v.view.contentScaleFactor = MaterialDevice.scale
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
}
}
/// A method that prepares the gestures used within the leftView.
private func prepareLeftViewGestures() {
prepareLeftPanGesture()
......
......@@ -31,7 +31,7 @@
import UIKit
@IBDesignable
public class BarController : UIViewController {
public class RootController : UIViewController {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
......@@ -92,6 +92,11 @@ public class BarController : UIViewController {
prepareView()
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/**
A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap
......@@ -118,19 +123,25 @@ public class BarController : UIViewController {
options: options,
animations: animations,
completion: { [weak self] (result: Bool) in
if let s: BarController = self {
if let s: RootController = 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)
}
})
}
/**
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,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
......@@ -144,7 +155,7 @@ public class BarController : UIViewController {
}
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
internal func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view)
}
......@@ -156,14 +167,15 @@ public class BarController : UIViewController {
- 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) {
internal func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.view.contentScaleFactor = MaterialDevice.scale
}
}
}
......@@ -48,17 +48,17 @@ public extension UIViewController {
}
}
public class SearchBarController : BarController {
public class SearchBarController : RootController {
/// Reference to the SearchBar.
public private(set) var searchBar: SearchBar!
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/// Layout subviews.
public func layoutSubviews() {
/**
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()
if let v: SearchBar = searchBar {
v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20
......
......@@ -49,111 +49,19 @@ public extension UIViewController {
}
@IBDesignable
public class StatusBarController : UIViewController {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
public class StatusBarController : RootController {
/// A reference to the statusBarView.
public private(set) var statusBarView: MaterialView!
/**
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.
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 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: 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)
}
})
public override func layoutSubviews() {
super.layoutSubviews()
statusBarView.hidden = MaterialDevice.isLandscape && .iPhone == MaterialDevice.type
rootViewController.view.frame = view.bounds
}
/**
......@@ -163,11 +71,9 @@ public class StatusBarController : UIViewController {
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
public override func prepareView() {
super.prepareView()
prepareStatusBarView()
prepareRootViewController()
}
/// Prepares the statusBarView.
......@@ -177,34 +83,4 @@ public class StatusBarController : UIViewController {
statusBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.12)
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 {
}
@objc(ToolbarController)
public class ToolbarController : BarController {
public class ToolbarController : RootController {
/// Internal reference to the floatingViewController.
private var internalFloatingViewController: UIViewController?
......@@ -151,13 +151,13 @@ public class ToolbarController : BarController {
}
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/// Layout subviews.
public func layoutSubviews() {
/**
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()
if let v: Toolbar = toolbar {
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