RDSRootControl.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. @interface RDSRootControl ()
  14. @property (nonatomic, strong) UIViewController *rootViewController;
  15. @property (nonatomic, strong) UIViewController *loginVC;
  16. //@property (nonatomic, strong) UIViewController *indexVC;
  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. }
  34. else {
  35. // 是否有设置过密码
  36. if(TheDataManager.isSetPassword){
  37. _rootViewController = [[RDSNavController alloc] initWithRootViewController:[[RDSLoginPwdCodeVC alloc] init]];
  38. }else{
  39. _rootViewController = [[RDSNavController alloc] initWithRootViewController:[[RDSLoginVerifyCodeVC alloc] init]];
  40. }
  41. }
  42. return _rootViewController;
  43. }
  44. - (UIViewController *)resetRootController{
  45. _rootViewController = [[RDSTabbarController alloc] init];
  46. _haveLogined = YES;
  47. return _rootViewController;
  48. }
  49. - (BOOL)isLoginSuccess{
  50. // _isLoginSuccess = TheDataManager.isStartAgain;
  51. return _isLoginSuccess;
  52. }
  53. - (void)setIsLoginSuccess:(BOOL)isLoginSuccess {
  54. if(isLoginSuccess == NO){
  55. [TheDataManager rds_cacheClean];
  56. }
  57. if (_isLoginSuccess != isLoginSuccess) {
  58. _isLoginSuccess = isLoginSuccess;
  59. // _rootViewController = self.indexVC;
  60. _needPushToHome = YES;
  61. [self p_chanceRootViewController:UIViewAnimationOptionTransitionCrossDissolve];
  62. }
  63. }
  64. - (void)p_chanceRootViewController:(UIViewAnimationOptions )options {
  65. typedef void (^Animation)(void);
  66. UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
  67. // self.rootViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  68. RDS_WEAKSELF(weakSelf)
  69. Animation animation = ^{
  70. BOOL oldState = [UIView areAnimationsEnabled];
  71. [UIView setAnimationsEnabled:NO];
  72. window.rootViewController = weakSelf.rootViewController;
  73. [UIView setAnimationsEnabled:oldState];
  74. };
  75. [UIView transitionWithView:window
  76. duration:0.3f
  77. options:options
  78. animations:animation
  79. completion:nil];
  80. }
  81. @end