Commit 5c193224 by Daniel Dahan

updated mainViewController references to rootViewController

parent 30004d7d
...@@ -39,14 +39,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,14 +39,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let bottomNavigationController: BottomNavigationController = BottomNavigationController() let bottomNavigationController: BottomNavigationController = BottomNavigationController()
bottomNavigationController.viewControllers = [AppMenuViewController(mainViewController: AppNavigationController(rootViewController: RecipesViewController())), VideoViewController(), PhotoViewController()] bottomNavigationController.viewControllers = [AppMenuViewController(rootViewController: AppNavigationController(rootViewController: RecipesViewController())), VideoViewController(), PhotoViewController()]
bottomNavigationController.selectedIndex = 0 bottomNavigationController.selectedIndex = 0
bottomNavigationController.tabBar.tintColor = MaterialColor.lightBlue.base bottomNavigationController.tabBar.tintColor = MaterialColor.lightBlue.base
bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4 bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = SideNavigationController(mainViewController: bottomNavigationController, leftViewController: AppLeftViewController(), rightViewController: AppRightViewController()) window!.rootViewController = SideNavigationController(rootViewController: bottomNavigationController, leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -34,7 +34,11 @@ import Material ...@@ -34,7 +34,11 @@ import Material
class AppNavigationController: NavigationController { class AppNavigationController: NavigationController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareNavigationBar()
}
/// Prepares the navigationBar
private func prepareNavigationBar() {
navigationBar.statusBarStyle = .LightContent navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
......
...@@ -75,7 +75,7 @@ class RecipesViewController: UIViewController { ...@@ -75,7 +75,7 @@ class RecipesViewController: UIViewController {
// Show the menuView. // Show the menuView.
menuViewController?.menuView.animate(MaterialAnimation.animationGroup([ menuViewController?.menuView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 3), MaterialAnimation.rotate(rotation: 3),
MaterialAnimation.translateY(0) MaterialAnimation.translateY(0 - tabBarController!.tabBar.frame.height)
])) ]))
} }
...@@ -87,7 +87,7 @@ class RecipesViewController: UIViewController { ...@@ -87,7 +87,7 @@ class RecipesViewController: UIViewController {
// Hide the menuView. // Hide the menuView.
menuViewController?.menuView.animate(MaterialAnimation.animationGroup([ menuViewController?.menuView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 3), MaterialAnimation.rotate(rotation: 3),
MaterialAnimation.translateY(150) MaterialAnimation.translateY(150 + tabBarController!.tabBar.frame.height)
])) ]))
} }
...@@ -103,7 +103,7 @@ class RecipesViewController: UIViewController { ...@@ -103,7 +103,7 @@ class RecipesViewController: UIViewController {
recommended.append(dataSourceItems[3]) recommended.append(dataSourceItems[3])
recommended.append(dataSourceItems[5]) recommended.append(dataSourceItems[5])
let vc: AppSearchBarController = AppSearchBarController(mainViewController: RecommendationViewController(dataSourceItems: recommended)) let vc: AppSearchBarController = AppSearchBarController(rootViewController: RecommendationViewController(dataSourceItems: recommended))
vc.modalTransitionStyle = .CrossDissolve vc.modalTransitionStyle = .CrossDissolve
navigationController?.presentViewController(vc, animated: true, completion: nil) navigationController?.presentViewController(vc, animated: true, completion: nil)
} }
......
...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = AppMenuViewController(mainViewController: YellowViewController()) window!.rootViewController = AppMenuViewController(rootViewController: YellowViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -49,46 +49,46 @@ class AppMenuViewController: MenuViewController { ...@@ -49,46 +49,46 @@ class AppMenuViewController: MenuViewController {
prepareMenuView() prepareMenuView()
} }
/// Loads the BlueViewController into the menuViewControllers mainViewController. /// Loads the BlueViewController into the menuViewControllers rootViewController.
func handleBlueButton() { func handleBlueButton() {
if mainViewController is BlueViewController { if rootViewController is BlueViewController {
return return
} }
closeMenu { [weak self] in closeMenu { [weak self] in
self?.transitionFromMainViewController(BlueViewController(), options: [.TransitionCrossDissolve]) self?.transitionFromRootViewController(BlueViewController(), options: [.TransitionCrossDissolve])
} }
} }
/// Loads the GreenViewController into the menuViewControllers mainViewController. /// Loads the GreenViewController into the menuViewControllers rootViewController.
func handleGreenButton() { func handleGreenButton() {
if mainViewController is GreenViewController { if rootViewController is GreenViewController {
return return
} }
closeMenu { [weak self] in closeMenu { [weak self] in
self?.transitionFromMainViewController(GreenViewController(), options: [.TransitionCrossDissolve]) self?.transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
} }
} }
/// Loads the YellowViewController into the menuViewControllers mainViewController. /// Loads the YellowViewController into the menuViewControllers rootViewController.
func handleYellowButton() { func handleYellowButton() {
// if (mainViewController as? ToolbarController)?.mainViewController is YellowViewController { // if (rootViewController as? ToolbarController)?.rootViewController is YellowViewController {
// return // return
// } // }
closeMenu { [weak self] in closeMenu { [weak self] in
self?.transitionFromMainViewController(YellowViewController(), options: [.TransitionCrossDissolve]) self?.transitionFromRootViewController(YellowViewController(), options: [.TransitionCrossDissolve])
} }
} }
/// Handle the menuView touch event. /// Handle the menuView touch event.
func handleMenu() { func handleMenu() {
if menuView.menu.opened { if menuView.menu.opened {
menuViewController?.mainViewController.view.alpha = 1 menuViewController?.rootViewController.view.alpha = 1
closeMenu() closeMenu()
} else { } else {
menuViewController?.mainViewController.view.alpha = 0.5 menuViewController?.rootViewController.view.alpha = 0.5
openMenu() openMenu()
} }
} }
......
...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = AppSearchBarController(mainViewController: YellowViewController()) window!.rootViewController = AppSearchBarController(rootViewController: YellowViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -43,28 +43,28 @@ class AppSearchBarController: SearchBarController { ...@@ -43,28 +43,28 @@ class AppSearchBarController: SearchBarController {
prepareSearchBar() prepareSearchBar()
} }
/// Loads the BlueViewController into the searchBarControllers mainViewController. /// Loads the BlueViewController into the searchBarControllers rootViewController.
func handleBlueButton() { func handleBlueButton() {
if mainViewController is BlueViewController { if rootViewController is BlueViewController {
return return
} }
transitionFromMainViewController(BlueViewController(), options: [.TransitionCrossDissolve]) transitionFromRootViewController(BlueViewController(), options: [.TransitionCrossDissolve])
} }
/// Loads the GreenViewController into the searchBarControllers mainViewController. /// Loads the GreenViewController into the searchBarControllers rootViewController.
func handleGreenButton() { func handleGreenButton() {
if mainViewController is GreenViewController { if rootViewController is GreenViewController {
return return
} }
transitionFromMainViewController(GreenViewController(), options: [.TransitionCrossDissolve]) transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
} }
/// Loads the YellowViewController into the searchBarControllers mainViewController. /// Loads the YellowViewController into the searchBarControllers rootViewController.
func handleYellowButton() { func handleYellowButton() {
if (mainViewController as? ToolbarController)?.mainViewController is YellowViewController { if (rootViewController as? ToolbarController)?.rootViewController is YellowViewController {
return return
} }
transitionFromMainViewController(YellowViewController(), options: [.TransitionCrossDissolve]) transitionFromRootViewController(YellowViewController(), options: [.TransitionCrossDissolve])
searchBar.textField.resignFirstResponder() searchBar.textField.resignFirstResponder()
} }
...@@ -128,12 +128,12 @@ class AppSearchBarController: SearchBarController { ...@@ -128,12 +128,12 @@ class AppSearchBarController: SearchBarController {
extension AppSearchBarController: TextFieldDelegate { extension AppSearchBarController: TextFieldDelegate {
func textFieldDidBeginEditing(textField: UITextField) { func textFieldDidBeginEditing(textField: UITextField) {
mainViewController.view.alpha = 0.5 rootViewController.view.alpha = 0.5
mainViewController.view.userInteractionEnabled = false rootViewController.view.userInteractionEnabled = false
} }
func textFieldDidEndEditing(textField: UITextField) { func textFieldDidEndEditing(textField: UITextField) {
mainViewController.view.alpha = 1 rootViewController.view.alpha = 1
mainViewController.view.userInteractionEnabled = true rootViewController.view.userInteractionEnabled = true
} }
} }
...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = SideNavigationController(mainViewController: YellowViewController(), leftViewController: GreenViewController(), rightViewController: BlueViewController()) window!.rootViewController = SideNavigationController(rootViewController: YellowViewController(), leftViewController: GreenViewController(), rightViewController: BlueViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = AppToolbarController(mainViewController: YellowViewController()) window!.rootViewController = AppToolbarController(rootViewController: YellowViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -61,7 +61,7 @@ class AppToolbarController: ToolbarController { ...@@ -61,7 +61,7 @@ class AppToolbarController: ToolbarController {
/// Toggle SideNavigationController left UIViewController. /// Toggle SideNavigationController left UIViewController.
internal func handleMenuButton() { internal func handleMenuButton() {
transitionFromMainViewController(GreenViewController(), options: [.TransitionCrossDissolve]) transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
} }
/// Toggle SideNavigationController right UIViewController. /// Toggle SideNavigationController right UIViewController.
...@@ -125,7 +125,7 @@ class AppToolbarController: ToolbarController { ...@@ -125,7 +125,7 @@ class AppToolbarController: ToolbarController {
extension AppToolbarController: MaterialSwitchDelegate { extension AppToolbarController: MaterialSwitchDelegate {
func materialSwitchStateChanged(control: MaterialSwitch) { func materialSwitchStateChanged(control: MaterialSwitch) {
transitionFromMainViewController(YellowViewController(), options: [.TransitionCrossDissolve]) transitionFromRootViewController(YellowViewController(), options: [.TransitionCrossDissolve])
} }
} }
...@@ -40,12 +40,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -40,12 +40,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Get view controllers from storyboard // Get view controllers from storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil) let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController let rootViewController = storyboard.instantiateViewControllerWithIdentifier("RootViewController") as! RootViewController
let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController
// Configure the window with the SideNavigationController as the root view controller // Configure the window with the SideNavigationController as the root view controller
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = SideNavigationController(mainViewController: mainViewController, leftViewController: sideViewController) window?.rootViewController = SideNavigationController(rootViewController: rootViewController, leftViewController: sideViewController)
window?.makeKeyAndVisible() window?.makeKeyAndVisible()
return true return true
} }
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--Main View Controller--> <!--Root View Controller-->
<scene sceneID="S32-pp-djU"> <scene sceneID="S32-pp-djU">
<objects> <objects>
<viewController storyboardIdentifier="MainViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="huh-WT-4zU" customClass="MainViewController" customModule="SideNavigationViewController" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="RootViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="huh-WT-4zU" customClass="RootViewController" customModule="SideNavigationViewController" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides> <layoutGuides>
<viewControllerLayoutGuide type="top" id="778-lO-FMj"/> <viewControllerLayoutGuide type="top" id="778-lO-FMj"/>
<viewControllerLayoutGuide type="bottom" id="hvu-kv-aLI"/> <viewControllerLayoutGuide type="bottom" id="hvu-kv-aLI"/>
...@@ -16,7 +15,6 @@ ...@@ -16,7 +15,6 @@
<view key="view" contentMode="scaleToFill" id="I6q-Is-0pO"> <view key="view" contentMode="scaleToFill" id="I6q-Is-0pO">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" red="0.3590823447" green="0.30467909450000003" blue="0.81552683250000002" alpha="1" colorSpace="calibratedRGB"/> <color key="backgroundColor" red="0.3590823447" green="0.30467909450000003" blue="0.81552683250000002" alpha="1" colorSpace="calibratedRGB"/>
</view> </view>
</viewController> </viewController>
...@@ -35,7 +33,6 @@ ...@@ -35,7 +33,6 @@
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/> <color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
</view> </view>
</viewController> </viewController>
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import UIKit import UIKit
import Material import Material
class MainViewController: UIViewController { class RootViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib. // Do any additional setup after loading the view, typically from a nib.
......
...@@ -112,14 +112,19 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -112,14 +112,19 @@ public class BottomNavigationController : UITabBarController, UITabBarController
public func prepareView() { public func prepareView() {
view.clipsToBounds = true view.clipsToBounds = true
delegate = self delegate = self
tabBar.depth = .Depth1 prepareTabBar()
tabBar.backgroundColor = MaterialColor.white
tabBar.shadowImage = UIImage.imageWithColor(MaterialColor.clear, size: CGSizeMake(1, 1))
tabBar.backgroundImage = UIImage()
} }
/// Handles transitions when tabBarItems are pressed. /// Handles transitions when tabBarItems are pressed.
public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
} }
/// Prepares the tabBar.
private func prepareTabBar() {
tabBar.depth = .Depth1
tabBar.backgroundColor = MaterialColor.white
tabBar.shadowImage = UIImage.imageWithColor(MaterialColor.clear, size: CGSizeMake(1, 1))
tabBar.backgroundImage = UIImage()
}
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.37.3</string> <string>1.38.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -55,32 +55,32 @@ public class MenuViewController : UIViewController { ...@@ -55,32 +55,32 @@ public class MenuViewController : UIViewController {
/** /**
A Boolean property used to enable and disable interactivity A Boolean property used to enable and disable interactivity
with the mainViewController. with the rootViewController.
*/ */
@IBInspectable public var userInteractionEnabled: Bool { @IBInspectable public var userInteractionEnabled: Bool {
get { get {
return mainViewController.view.userInteractionEnabled return rootViewController.view.userInteractionEnabled
} }
set(value) { set(value) {
mainViewController.view.userInteractionEnabled = value rootViewController.view.userInteractionEnabled = value
} }
} }
/** /**
A UIViewController property that references the active A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it main UIViewController. To swap the rootViewController, it
is recommended to use the transitionFromMainViewController is recommended to use the transitionFromRootViewController
helper method. helper method.
*/ */
public private(set) var mainViewController: UIViewController! public private(set) var rootViewController: UIViewController!
/** /**
An initializer for the MenuViewController. An initializer for the MenuViewController.
- Parameter mainViewController: The main UIViewController. - Parameter rootViewController: The main UIViewController.
*/ */
public convenience init(mainViewController: UIViewController) { public convenience init(rootViewController: UIViewController) {
self.init() self.init()
self.mainViewController = mainViewController self.rootViewController = rootViewController
prepareView() prepareView()
} }
...@@ -90,35 +90,37 @@ public class MenuViewController : UIViewController { ...@@ -90,35 +90,37 @@ public class MenuViewController : UIViewController {
} }
/** /**
A method to swap mainViewController objects. A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap - Parameter toViewController: The UIViewController to swap
with the active mainViewController. with the active rootViewController.
- Parameter duration: A NSTimeInterval that sets the - Parameter duration: A NSTimeInterval that sets the
animation duration of the transition. animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used - Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController when animating the transition from the active rootViewController
to the toViewController. to the toViewController.
- Parameter animations: An animation block that is executed during - Parameter animations: An animation block that is executed during
the transition from the active mainViewController the transition from the active rootViewController
to the toViewController. to the toViewController.
- Parameter completion: A completion block that is execited after - Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController the transition animation from the active rootViewController
to the toViewController has completed. to the toViewController has completed.
*/ */
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { public func transitionFromRootViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
mainViewController.willMoveToParentViewController(nil) rootViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController) addChildViewController(toViewController)
toViewController.view.frame = mainViewController.view.frame toViewController.view.frame = rootViewController.view.frame
transitionFromViewController(mainViewController, transitionFromViewController(rootViewController,
toViewController: toViewController, toViewController: toViewController,
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [unowned self] (result: Bool) in completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self) toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController() self.rootViewController.removeFromParentViewController()
self.mainViewController = toViewController self.rootViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view) self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth
self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result) completion?(result)
}) })
} }
...@@ -131,7 +133,7 @@ public class MenuViewController : UIViewController { ...@@ -131,7 +133,7 @@ public class MenuViewController : UIViewController {
public func openMenu(completion: (() -> Void)? = nil) { public func openMenu(completion: (() -> Void)? = nil) {
if true == userInteractionEnabled { if true == userInteractionEnabled {
userInteractionEnabled = false userInteractionEnabled = false
mainViewController.view.alpha = 0.5 rootViewController.view.alpha = 0.5
menuView.open(completion) menuView.open(completion)
} }
} }
...@@ -143,7 +145,7 @@ public class MenuViewController : UIViewController { ...@@ -143,7 +145,7 @@ public class MenuViewController : UIViewController {
*/ */
public func closeMenu(completion: (() -> Void)? = nil) { public func closeMenu(completion: (() -> Void)? = nil) {
if false == userInteractionEnabled { if false == userInteractionEnabled {
mainViewController.view.alpha = 1 rootViewController.view.alpha = 1
menuView.close({ [weak self] in menuView.close({ [weak self] in
self?.userInteractionEnabled = true self?.userInteractionEnabled = true
completion?() completion?()
...@@ -153,10 +155,9 @@ public class MenuViewController : UIViewController { ...@@ -153,10 +155,9 @@ public class MenuViewController : UIViewController {
/// A method that generally prepares the MenuViewController. /// A method that generally prepares the MenuViewController.
private func prepareView() { private func prepareView() {
edgesForExtendedLayout = .None
view.clipsToBounds = true view.clipsToBounds = true
prepareMenuView() prepareMenuView()
prepareMainViewController() prepareRootViewController()
} }
/// Prepares the MenuView. /// Prepares the MenuView.
...@@ -165,9 +166,11 @@ public class MenuViewController : UIViewController { ...@@ -165,9 +166,11 @@ public class MenuViewController : UIViewController {
view.addSubview(menuView) view.addSubview(menuView)
} }
/// A method that prepares the mainViewController. /// A method that prepares the rootViewController.
private func prepareMainViewController() { private func prepareRootViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view) rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth
prepareViewControllerWithinContainer(rootViewController, container: view)
} }
/** /**
...@@ -181,13 +184,14 @@ public class MenuViewController : UIViewController { ...@@ -181,13 +184,14 @@ public class MenuViewController : UIViewController {
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) { private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController { if let v: UIViewController = viewController {
addChildViewController(v) addChildViewController(v)
container.insertSubview(v.view, atIndex: 0) container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self) v.didMoveToParentViewController(self)
} }
} }
/// Layout subviews. /// Layout subviews.
private func layoutSubviews() { private func layoutSubviews() {
mainViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
} }
} }
...@@ -60,8 +60,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -60,8 +60,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
public override func viewDidLoad() { public override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
edgesForExtendedLayout = .None prepareView()
view.clipsToBounds = true
// This ensures the panning gesture is available when going back between views. // This ensures the panning gesture is available when going back between views.
if let v: UIGestureRecognizer = interactivePopGestureRecognizer { if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
...@@ -128,4 +127,9 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -128,4 +127,9 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
internal func handleBackButton() { internal func handleBackButton() {
popViewControllerAnimated(true) popViewControllerAnimated(true)
} }
/// Prepares the view.
private func prepareView() {
view.clipsToBounds = true
}
} }
...@@ -43,65 +43,67 @@ public class StatusBarViewController : UIViewController { ...@@ -43,65 +43,67 @@ public class StatusBarViewController : UIViewController {
/** /**
A Boolean property used to enable and disable interactivity A Boolean property used to enable and disable interactivity
with the mainViewController. with the rootViewController.
*/ */
@IBInspectable public var userInteractionEnabled: Bool { @IBInspectable public var userInteractionEnabled: Bool {
get { get {
return mainViewController.view.userInteractionEnabled return rootViewController.view.userInteractionEnabled
} }
set(value) { set(value) {
mainViewController.view.userInteractionEnabled = value rootViewController.view.userInteractionEnabled = value
} }
} }
/** /**
A UIViewController property that references the active A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it main UIViewController. To swap the rootViewController, it
is recommended to use the transitionFromMainViewController is recommended to use the transitionFromRootViewController
helper method. helper method.
*/ */
public private(set) var mainViewController: UIViewController! public private(set) var rootViewController: UIViewController!
/** /**
An initializer for the StatusBarViewController. An initializer for the StatusBarViewController.
- Parameter mainViewController: The main UIViewController. - Parameter rootViewController: The main UIViewController.
*/ */
public convenience init(mainViewController: UIViewController) { public convenience init(rootViewController: UIViewController) {
self.init() self.init()
self.mainViewController = mainViewController self.rootViewController = rootViewController
prepareView() prepareView()
} }
/** /**
A method to swap mainViewController objects. A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap - Parameter toViewController: The UIViewController to swap
with the active mainViewController. with the active rootViewController.
- Parameter duration: A NSTimeInterval that sets the - Parameter duration: A NSTimeInterval that sets the
animation duration of the transition. animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used - Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController when animating the transition from the active rootViewController
to the toViewController. to the toViewController.
- Parameter animations: An animation block that is executed during - Parameter animations: An animation block that is executed during
the transition from the active mainViewController the transition from the active rootViewController
to the toViewController. to the toViewController.
- Parameter completion: A completion block that is execited after - Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController the transition animation from the active rootViewController
to the toViewController has completed. to the toViewController has completed.
*/ */
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { public func transitionFromRootViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
mainViewController.willMoveToParentViewController(nil) rootViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController) addChildViewController(toViewController)
toViewController.view.frame = mainViewController.view.frame toViewController.view.frame = rootViewController.view.frame
transitionFromViewController(mainViewController, transitionFromViewController(rootViewController,
toViewController: toViewController, toViewController: toViewController,
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [unowned self] (result: Bool) in completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self) toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController() self.rootViewController.removeFromParentViewController()
self.mainViewController = toViewController self.rootViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view) self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth
self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result) completion?(result)
}) })
} }
...@@ -114,9 +116,8 @@ public class StatusBarViewController : UIViewController { ...@@ -114,9 +116,8 @@ public class StatusBarViewController : UIViewController {
when subclassing. when subclassing.
*/ */
public func prepareView() { public func prepareView() {
edgesForExtendedLayout = .None
view.clipsToBounds = true view.clipsToBounds = true
prepareMainViewController() prepareRootViewController()
} }
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
...@@ -130,18 +131,19 @@ public class StatusBarViewController : UIViewController { ...@@ -130,18 +131,19 @@ public class StatusBarViewController : UIViewController {
let q: CGFloat = UIApplication.sharedApplication().statusBarFrame.size.height let q: CGFloat = UIApplication.sharedApplication().statusBarFrame.size.height
if .iPhone == MaterialDevice.type && MaterialDevice.landscape { if .iPhone == MaterialDevice.type && MaterialDevice.landscape {
mainViewController.view.frame.origin.y = heightForLandscapeOrientation rootViewController.view.frame.origin.y = heightForLandscapeOrientation
mainViewController.view.frame.size.height = h - (heightForStatusBar >= q ? heightForLandscapeOrientation : q - heightForStatusBar - heightForLandscapeOrientation) rootViewController.view.frame.size.height = h - (heightForStatusBar >= q ? heightForLandscapeOrientation : q - heightForStatusBar - heightForLandscapeOrientation)
} else { } else {
mainViewController.view.frame.origin.y = heightForPortraitOrientation rootViewController.view.frame.origin.y = heightForPortraitOrientation
mainViewController.view.frame.size.height = h - (heightForStatusBar >= q ? heightForPortraitOrientation : q - heightForStatusBar - heightForPortraitOrientation) rootViewController.view.frame.size.height = h - (heightForStatusBar >= q ? heightForPortraitOrientation : q - heightForStatusBar - heightForPortraitOrientation)
} }
} }
/// A method that prepares the mainViewController. /// A method that prepares the rootViewController.
private func prepareMainViewController() { private func prepareRootViewController() {
mainViewController.view.autoresizingMask = .FlexibleWidth rootViewController.view.clipsToBounds = true
prepareViewControllerWithinContainer(mainViewController, container: view) rootViewController.view.autoresizingMask = .FlexibleWidth
prepareViewControllerWithinContainer(rootViewController, container: view)
} }
/** /**
...@@ -155,7 +157,8 @@ public class StatusBarViewController : UIViewController { ...@@ -155,7 +157,8 @@ public class StatusBarViewController : UIViewController {
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) { private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController { if let v: UIViewController = viewController {
addChildViewController(v) addChildViewController(v)
container.insertSubview(v.view, atIndex: 0) container.addSubview(v.view)
container.sendSubviewToBack(v.view)
v.didMoveToParentViewController(self) v.didMoveToParentViewController(self)
} }
} }
......
...@@ -119,7 +119,7 @@ public class ToolbarController : StatusBarViewController { ...@@ -119,7 +119,7 @@ public class ToolbarController : StatusBarViewController {
animations: { [unowned self] in animations: { [unowned self] in
v.view.center.y = 2 * self.view.bounds.height v.view.center.y = 2 * self.view.bounds.height
self.toolbar.alpha = 1 self.toolbar.alpha = 1
self.mainViewController.view.alpha = 1 self.rootViewController.view.alpha = 1
}) { [unowned self] _ in }) { [unowned self] _ in
v.willMoveToParentViewController(nil) v.willMoveToParentViewController(nil)
v.view.removeFromSuperview() v.view.removeFromSuperview()
...@@ -157,7 +157,7 @@ public class ToolbarController : StatusBarViewController { ...@@ -157,7 +157,7 @@ public class ToolbarController : StatusBarViewController {
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
self.toolbar.alpha = 0.5 self.toolbar.alpha = 0.5
self.mainViewController.view.alpha = 0.5 self.rootViewController.view.alpha = 0.5
}) { [unowned self] _ in }) { [unowned self] _ in
v.view.layer.shouldRasterize = false v.view.layer.shouldRasterize = false
self.view.layer.shouldRasterize = false self.view.layer.shouldRasterize = false
......
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