// // RDSRootControl.m // SmartLightForBigFish // // Created by coderYK on 2017/8/7. // Copyright © 2017年 RD-iOS. All rights reserved. // #import "RDSRootControl.h" #import "RDSNavController.h" #import "RDSLoginPwdCodeVC.h" #import "RDSLoginVerifyCodeVC.h" #import "RDSTabbarController.h" #import "YXGuideViewController.h" @interface RDSRootControl () @property (nonatomic, strong) UIViewController *rootViewController; @property (nonatomic, strong) UIViewController *loginVC; @property (nonatomic, assign) BOOL needPushToHome; // ** <#注释#>*/ @end @implementation RDSRootControl @synthesize isLoginSuccess = _isLoginSuccess; + (instancetype)shareControl { static RDSRootControl *_instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (UIViewController *)rootViewController { if (self.isLoginSuccess) { _rootViewController = [[RDSTabbarController alloc] init]; _haveLogined = YES; if (_isFirst == YES) { YXGuideViewController *guideVc = [[YXGuideViewController alloc]init]; [_rootViewController addChildViewController:guideVc]; [_rootViewController.view addSubview:guideVc.view]; guideVc.view.frame = _rootViewController.view.bounds; } } else { // 是否有设置过密码 // if(TheDataManager.isSetPassword){ RDSLoginPwdCodeVC *pwdVc = [[RDSLoginPwdCodeVC alloc] init]; _rootViewController = [[RDSNavController alloc] initWithRootViewController:pwdVc]; if (_isFirst == YES) { YXGuideViewController *guideVc = [[YXGuideViewController alloc]init]; [pwdVc addChildViewController:guideVc]; [pwdVc.view addSubview:guideVc.view]; guideVc.view.frame = pwdVc.view.bounds; } // }else{ // RDSLoginVerifyCodeVC *codeVc = [[RDSLoginVerifyCodeVC alloc] init]; // _rootViewController = [[RDSNavController alloc] initWithRootViewController:codeVc]; // // if (_isFirst == YES) { // YXGuideViewController *guideVc = [[YXGuideViewController alloc]init]; // [codeVc addChildViewController:guideVc]; // [codeVc.view addSubview:guideVc.view]; // guideVc.view.frame = codeVc.view.bounds; // } // } } return _rootViewController; } - (void)setIsLoginSuccess:(BOOL)isLoginSuccess { if(isLoginSuccess == NO){ [TheDataManager rds_cacheClean]; } if (_isLoginSuccess != isLoginSuccess) { _isLoginSuccess = isLoginSuccess; _needPushToHome = YES; _isFirst = NO; [self p_changeRootViewController:UIViewAnimationOptionCurveEaseOut]; } } - (void)p_changeRootViewController:(UIViewAnimationOptions )options { typedef void (^Animation)(void); UIWindow* window = [[[UIApplication sharedApplication] delegate] window]; RDS_WEAKSELF(weakSelf) Animation animation = ^{ BOOL oldState = [UIView areAnimationsEnabled]; [UIView setAnimationsEnabled:NO]; window.rootViewController = weakSelf.rootViewController; [UIView setAnimationsEnabled:oldState]; }; [UIView transitionWithView:window duration:0.3f options:options animations:animation completion:nil]; } @end