YBBaseAppDelegate.m 3.3 KB

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