Advertisement
Guest User

Untitled

a guest
May 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. @implementation UINavigationController (MHAutorotation)
  2.  
  3. - (BOOL)shouldAutorotate {
  4. return [self.topViewController shouldAutorotate];
  5. }
  6.  
  7. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  8. return [self.topViewController supportedInterfaceOrientations];
  9. }
  10.  
  11. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  12. return [self.topViewController preferredInterfaceOrientationForPresentation];
  13. }
  14.  
  15. - (UIViewController *)childViewControllerForStatusBarStyle {
  16. return self.topViewController;
  17. }
  18.  
  19. - (UIViewController *)childViewControllerForStatusBarHidden {
  20. return self.topViewController;
  21. }
  22.  
  23. @end
  24.  
  25. @implementation UITabBarController (MHAutorotation)
  26.  
  27. - (BOOL)shouldAutorotate {
  28. UIViewController *vc = self.viewControllers[self.selectedIndex];
  29. if ([vc isKindOfClass:[UINavigationController class]]) {
  30. UINavigationController *nav = (UINavigationController *)vc;
  31. return [nav.topViewController shouldAutorotate];
  32. }
  33. else {
  34. return [vc shouldAutorotate];
  35. }
  36. }
  37.  
  38. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  39. UIViewController *vc = self.viewControllers[self.selectedIndex];
  40. if ([vc isKindOfClass:[UINavigationController class]]) {
  41. UINavigationController *nav = (UINavigationController *)vc;
  42. return [nav.topViewController supportedInterfaceOrientations];
  43. }
  44. else {
  45. return [vc supportedInterfaceOrientations];
  46. }
  47. }
  48.  
  49. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  50. UIViewController *vc = self.viewControllers[self.selectedIndex];
  51. if ([vc isKindOfClass:[UINavigationController class]]) {
  52. UINavigationController *nav = (UINavigationController *)vc;
  53. return [nav.topViewController preferredInterfaceOrientationForPresentation];
  54. }
  55. else {
  56. return [vc preferredInterfaceOrientationForPresentation];
  57. }
  58. }
  59.  
  60. @end
  61.  
  62. @implementation UISplitViewController (MHAutorotation)
  63.  
  64.  
  65. - (BOOL)shouldAutorotate
  66. {
  67. UIViewController *vc = self.viewControllers.lastObject;
  68. if ([vc isKindOfClass:[UINavigationController class]]) {
  69. UINavigationController *nav = (UINavigationController *)vc;
  70. return [nav.topViewController shouldAutorotate];
  71. }
  72. else {
  73. return [vc shouldAutorotate];
  74. }
  75. }
  76.  
  77. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  78. {
  79. UIViewController *vc = self.viewControllers.lastObject;
  80. if ([vc isKindOfClass:[UINavigationController class]]) {
  81. UINavigationController *nav = (UINavigationController *)vc;
  82. return [nav.topViewController supportedInterfaceOrientations];
  83. }
  84. else {
  85. return [vc supportedInterfaceOrientations];
  86. }
  87. }
  88.  
  89. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  90. {
  91. UIViewController *vc = self.viewControllers.lastObject;
  92. if ([vc isKindOfClass:[UINavigationController class]]) {
  93. UINavigationController *nav = (UINavigationController *)vc;
  94. return [nav.topViewController preferredInterfaceOrientationForPresentation];
  95. }
  96. else {
  97. return [vc preferredInterfaceOrientationForPresentation];
  98. }
  99. }
  100.  
  101. - (UIViewController *)childViewControllerForStatusBarStyle
  102. {
  103. UIViewController *vc = self.viewControllers.lastObject;
  104. if ([vc isKindOfClass:[UINavigationController class]]) {
  105. UINavigationController *nav = (UINavigationController *)vc;
  106. return nav.topViewController;
  107. }
  108. else {
  109. return vc;
  110. }
  111. }
  112.  
  113. - (UIViewController *)childViewControllerForStatusBarHidden
  114. {
  115. UIViewController *vc = self.viewControllers.lastObject;
  116. if ([vc isKindOfClass:[UINavigationController class]]) {
  117. UINavigationController *nav = (UINavigationController *)vc;
  118. return nav.topViewController;
  119. }
  120. else {
  121. return vc;
  122. }
  123. }
  124.  
  125. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement