Created
November 15, 2012 14:25
-
-
Save robinhayward/4078857 to your computer and use it in GitHub Desktop.
NavigationController/TabBarController Transition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FASWindowState.m | |
// FAS | |
// | |
// Created by Rob Hayward on 14/11/2012. | |
// | |
#import "FASWindowState.h" | |
#import "FASWelcomeViewController.h" | |
#import "FASTeamsTabBarController.h" | |
#import "FASSettingsViewController.h" | |
@interface FASWindowState () | |
{ | |
UIViewController *_rootViewController; | |
} | |
@end | |
@implementation FASWindowState | |
- (id)initWithWindow:(UIWindow *)window | |
{ | |
self = [super init]; | |
if (self) { | |
_window = window; | |
[self notifications]; | |
[self displayForLoginState]; | |
} | |
return self; | |
} | |
#pragma mark - UI Setup | |
- (void)displayForLoginState | |
{ | |
FASUser *user = [[FASUserSession shared] user]; | |
if (!user) { | |
[self presentSignedOutInterface]; | |
} else { | |
[self presentSignedInInterface]; | |
} | |
} | |
#pragma mark - Notifications | |
- (void)notifications | |
{ | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userSignInComplete:) name:@"FASUserSignInDidCompleteNotification" object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userSignUpComplete:) name:@"FASUserSignUpDidCompleteNotification" object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsShow:) name:@"FASSettingsShouldShowNotification" object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsDismiss:) name:@"FASSettingsShouldDismissNotification" object:nil]; | |
} | |
- (void)userSignInComplete:(NSNotification *)notification | |
{ | |
FASTeamsTabBarController *controller = [[FASTeamsTabBarController alloc] initWithNibName:nil bundle:nil]; | |
[self updateWindowStateWithRootController:controller animated:YES track:YES]; | |
} | |
- (void)userSignUpComplete:(NSNotification *)notification | |
{ | |
FASTeamsTabBarController *controller = [[FASTeamsTabBarController alloc] initWithNibName:nil bundle:nil]; | |
[controller setThanks:YES]; | |
[self updateWindowStateWithRootController:controller animated:YES track:YES]; | |
} | |
- (void)settingsShow:(NSNotification *)notification | |
{ | |
FASSettingsViewController *viewController = [[FASSettingsViewController alloc] initWithNibName:nil bundle:nil]; | |
FASNavigationController *controller = [[FASNavigationController alloc] initWithRootViewController:viewController]; | |
[self updateWindowStateWithRootController:controller animated:YES track:NO]; | |
} | |
- (void)settingsDismiss:(NSNotification *)notification | |
{ | |
[self updateWindowStateWithRootController:_rootViewController animated:YES track:NO]; | |
} | |
#pragma mark - Actions | |
- (void)presentSignedOutInterface | |
{ | |
FASWelcomeViewController *welcome = [[FASWelcomeViewController alloc] initWithNibName:nil bundle:nil]; | |
FASNavigationController *controller = [[FASNavigationController alloc] initWithRootViewController:welcome]; | |
[self updateWindowStateWithRootController:controller animated:NO track:YES]; | |
} | |
- (void)presentSignedInInterface | |
{ | |
FASTeamsTabBarController *controller = [[FASTeamsTabBarController alloc] initWithNibName:nil bundle:nil]; | |
[_window setRootViewController:controller]; | |
[self updateWindowStateWithRootController:controller animated:NO track:YES]; | |
} | |
- (void)updateWindowStateWithRootController:(UIViewController *)viewController animated:(BOOL)animated track:(BOOL)track { | |
if (!animated) { | |
[_window setRootViewController:viewController]; | |
} else { | |
[UIView transitionWithView:_window duration:0.5 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{ | |
_window.rootViewController = viewController; | |
} completion:nil]; | |
} | |
if (track) { | |
_rootViewController = viewController; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment