Keine Beschreibung

LGAlertViewController.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // LGAlertViewController.h
  3. // LGAlertView
  4. //
  5. //
  6. // The MIT License (MIT)
  7. //
  8. // Copyright © 2015 Grigory Lutkov <Friend.LGA@gmail.com>
  9. // (https://github.com/Friend-LGA/LGAlertView)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining a copy
  12. // of this software and associated documentation files (the "Software"), to deal
  13. // in the Software without restriction, including without limitation the rights
  14. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. // copies of the Software, and to permit persons to whom the Software is
  16. // furnished to do so, subject to the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be included in all
  19. // copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. // SOFTWARE.
  28. //
  29. #import "LGAlertViewController.h"
  30. #import "LGAlertView.h"
  31. #import "UIWindow+LGAlertView.h"
  32. #import "LGAlertViewHelper.h"
  33. @interface LGAlertViewController ()
  34. @property (strong, nonatomic) LGAlertView *alertView;
  35. @end
  36. @implementation LGAlertViewController
  37. - (nonnull instancetype)initWithAlertView:(nonnull LGAlertView *)alertView view:(nonnull UIView *)view {
  38. self = [super init];
  39. if (self) {
  40. self.alertView = alertView;
  41. self.view.backgroundColor = UIColor.clearColor;
  42. [self.view addSubview:view];
  43. }
  44. return self;
  45. }
  46. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  47. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  48. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  49. [UIView animateWithDuration:coordinator.transitionDuration animations:^{
  50. [self setNeedsStatusBarAppearanceUpdate];
  51. [self.alertView layoutValidateWithSize:size];
  52. }];
  53. });
  54. }
  55. #pragma mark -
  56. - (BOOL)shouldAutorotate {
  57. UIViewController *viewController = LGAlertViewHelper.appWindow.currentViewController;
  58. if (viewController) {
  59. return viewController.shouldAutorotate;
  60. }
  61. return super.shouldAutorotate;
  62. }
  63. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  64. UIViewController *viewController = LGAlertViewHelper.appWindow.currentViewController;
  65. if (viewController) {
  66. return viewController.supportedInterfaceOrientations;
  67. }
  68. return super.supportedInterfaceOrientations;
  69. }
  70. - (UIStatusBarStyle)preferredStatusBarStyle {
  71. if (LGAlertViewHelper.isViewControllerBasedStatusBarAppearance) {
  72. UIViewController *viewController = LGAlertViewHelper.appWindow.currentViewController;
  73. if (viewController) {
  74. return viewController.preferredStatusBarStyle;
  75. }
  76. }
  77. return super.preferredStatusBarStyle;
  78. }
  79. - (BOOL)prefersStatusBarHidden {
  80. if (LGAlertViewHelper.isViewControllerBasedStatusBarAppearance) {
  81. UIViewController *viewController = LGAlertViewHelper.appWindow.currentViewController;
  82. if (viewController) {
  83. return viewController.prefersStatusBarHidden;
  84. }
  85. }
  86. return super.prefersStatusBarHidden;
  87. }
  88. - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
  89. if (LGAlertViewHelper.isViewControllerBasedStatusBarAppearance) {
  90. UIViewController *viewController = LGAlertViewHelper.appWindow.currentViewController;
  91. if (viewController) {
  92. return viewController.preferredStatusBarUpdateAnimation;
  93. }
  94. }
  95. return super.preferredStatusBarUpdateAnimation;
  96. }
  97. @end