TCBaseAppDelegate.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // TCBaseAppDelegate.m
  3. // TCLVBIMDemo
  4. //
  5. // Created by annidyfeng on 16/7/29.
  6. // Copyright © 2016年 tencent. All rights reserved.
  7. //
  8. #import "TCBaseAppDelegate.h"
  9. #import "TCNavigationController.h"
  10. //#import "moviePlay.h"
  11. @implementation TCBaseAppDelegate
  12. + (instancetype)sharedAppDelegate
  13. {
  14. return [UIApplication sharedApplication].delegate;
  15. }
  16. // 配置App中的控件的默认属性
  17. - (void)configAppearance
  18. {
  19. [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
  20. [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
  21. [[UILabel appearance] setBackgroundColor:[UIColor clearColor]];
  22. [[UILabel appearance] setTextColor:[UIColor blackColor]];
  23. [[UIButton appearance] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  24. }
  25. // 获取当前活动的navigationcontroller
  26. - (UINavigationController *)navigationViewController
  27. {
  28. UIWindow *window = self.window;
  29. if ([window.rootViewController isKindOfClass:[UINavigationController class]])
  30. {
  31. return (UINavigationController *)window.rootViewController;
  32. }
  33. else if ([window.rootViewController isKindOfClass:[UITabBarController class]])
  34. {
  35. UIViewController *selectVc = [((UITabBarController *)window.rootViewController) selectedViewController];
  36. if ([selectVc isKindOfClass:[UINavigationController class]])
  37. {
  38. return (UINavigationController *)selectVc;
  39. }
  40. }
  41. return nil;
  42. }
  43. - (UIViewController *)topViewController
  44. {
  45. UINavigationController *nav = [self navigationViewController];
  46. return nav.topViewController;
  47. }
  48. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  49. {
  50. @autoreleasepool
  51. {
  52. viewController.hidesBottomBarWhenPushed = YES;
  53. [[self navigationViewController] pushViewController:viewController animated:animated];
  54. }
  55. }
  56. - (UIViewController *)popViewController:(BOOL)animated
  57. {
  58. return [[self navigationViewController] popViewControllerAnimated:animated];
  59. }
  60. - (NSArray *)popToRootViewController
  61. {
  62. return [[self navigationViewController] popToRootViewControllerAnimated:NO];
  63. }
  64. - (NSArray *)popToViewController:(UIViewController *)viewController
  65. {
  66. return [[self navigationViewController] popToViewController:viewController animated:NO];
  67. }
  68. - (void)presentViewController:(UIViewController *)vc animated:(BOOL)animated completion:(void (^)())completion
  69. {
  70. UIViewController *top = [self topViewController];
  71. if (vc.navigationController == nil)
  72. {
  73. TCNavigationController *nav = [[TCNavigationController alloc] initWithRootViewController:vc];
  74. [top presentViewController:nav animated:animated completion:completion];
  75. }
  76. else
  77. {
  78. [top presentViewController:vc animated:animated completion:completion];
  79. }
  80. }
  81. - (void)dismissViewController:(UIViewController *)vc animated:(BOOL)animated completion:(void (^)())completion
  82. {
  83. if (vc.navigationController != [TCBaseAppDelegate sharedAppDelegate].navigationViewController)
  84. {
  85. [vc dismissViewControllerAnimated:YES completion:nil];
  86. }
  87. else
  88. {
  89. [self popViewController:animated];
  90. }
  91. }
  92. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  93. {
  94. [self configAppearance];
  95. return YES;
  96. }
  97. /*- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  98. {
  99. UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
  100. [navigationController shouldAutorotate];
  101. [navigationController preferredInterfaceOrientationForPresentation];
  102. if()
  103. {
  104. return UIInterfaceOrientationMaskAll;
  105. }
  106. else
  107. {
  108. return UIInterfaceOrientationMaskPortrait;
  109. }
  110. }
  111. */
  112. @end