RDSRootControl.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // RDSRootControl.m
  3. // SmartLightForBigFish
  4. //
  5. // Created by coderYK on 2017/8/7.
  6. // Copyright © 2017年 RD-iOS. All rights reserved.
  7. //
  8. #import "RDSRootControl.h"
  9. #import "RDSNavController.h"
  10. #import "RDSLoginPwdCodeVC.h"
  11. #import "RDSLoginVerifyCodeVC.h"
  12. #import "RDSTabbarController.h"
  13. #import "YXGuideViewController.h"
  14. @interface RDSRootControl ()
  15. @property (nonatomic, strong) UIViewController *rootViewController;
  16. @property (nonatomic, strong) UIViewController *loginVC;
  17. @property (nonatomic, assign) BOOL needPushToHome; // ** <#注释#>*/
  18. @end
  19. @implementation RDSRootControl
  20. @synthesize isLoginSuccess = _isLoginSuccess;
  21. + (instancetype)shareControl {
  22. static RDSRootControl *_instance = nil;
  23. static dispatch_once_t onceToken;
  24. dispatch_once(&onceToken, ^{
  25. _instance = [[self alloc] init];
  26. });
  27. return _instance;
  28. }
  29. - (UIViewController *)rootViewController {
  30. if (self.isLoginSuccess) {
  31. _rootViewController = [[RDSTabbarController alloc] init];
  32. _haveLogined = YES;
  33. if (_isFirst == YES) {
  34. YXGuideViewController *guideVc = [[YXGuideViewController alloc]init];
  35. [_rootViewController addChildViewController:guideVc];
  36. [_rootViewController.view addSubview:guideVc.view];
  37. guideVc.view.frame = _rootViewController.view.bounds;
  38. }
  39. } else {
  40. // 是否有设置过密码
  41. // if(TheDataManager.isSetPassword){
  42. RDSLoginPwdCodeVC *pwdVc = [[RDSLoginPwdCodeVC alloc] init];
  43. _rootViewController = [[RDSNavController alloc] initWithRootViewController:pwdVc];
  44. if (_isFirst == YES) {
  45. YXGuideViewController *guideVc = [[YXGuideViewController alloc]init];
  46. [pwdVc addChildViewController:guideVc];
  47. [pwdVc.view addSubview:guideVc.view];
  48. guideVc.view.frame = pwdVc.view.bounds;
  49. }
  50. // }else{
  51. // RDSLoginVerifyCodeVC *codeVc = [[RDSLoginVerifyCodeVC alloc] init];
  52. // _rootViewController = [[RDSNavController alloc] initWithRootViewController:codeVc];
  53. //
  54. // if (_isFirst == YES) {
  55. // YXGuideViewController *guideVc = [[YXGuideViewController alloc]init];
  56. // [codeVc addChildViewController:guideVc];
  57. // [codeVc.view addSubview:guideVc.view];
  58. // guideVc.view.frame = codeVc.view.bounds;
  59. // }
  60. // }
  61. }
  62. return _rootViewController;
  63. }
  64. - (void)setIsLoginSuccess:(BOOL)isLoginSuccess {
  65. if(isLoginSuccess == NO){
  66. [TheDataManager rds_cacheClean];
  67. }
  68. if (_isLoginSuccess != isLoginSuccess) {
  69. _isLoginSuccess = isLoginSuccess;
  70. _needPushToHome = YES;
  71. _isFirst = NO;
  72. [self p_changeRootViewController:UIViewAnimationOptionCurveEaseOut];
  73. }
  74. }
  75. - (void)p_changeRootViewController:(UIViewAnimationOptions )options {
  76. typedef void (^Animation)(void);
  77. UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
  78. RDS_WEAKSELF(weakSelf)
  79. Animation animation = ^{
  80. BOOL oldState = [UIView areAnimationsEnabled];
  81. [UIView setAnimationsEnabled:NO];
  82. window.rootViewController = weakSelf.rootViewController;
  83. [UIView setAnimationsEnabled:oldState];
  84. };
  85. [UIView transitionWithView:window
  86. duration:0.3f
  87. options:options
  88. animations:animation
  89. completion:nil];
  90. }
  91. @end