AHKActionSheetViewController.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // AHKActionSheetViewController.m
  3. // AHKActionSheetExample
  4. //
  5. // Created by Arkadiusz on 09-04-14.
  6. // Copyright (c) 2014 Arkadiusz Holko. All rights reserved.
  7. //
  8. #import "AHKActionSheetViewController.h"
  9. #import "AHKActionSheet.h"
  10. #import "UIWindow+AHKAdditions.h"
  11. @interface AHKActionSheetViewController ()
  12. @property (nonatomic) BOOL viewAlreadyAppear;
  13. @end
  14. @implementation AHKActionSheetViewController
  15. #pragma mark - UIViewController
  16. - (void)viewDidLoad
  17. {
  18. [super viewDidLoad];
  19. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotateDeviceChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
  20. [self.view addSubview:self.actionSheet];
  21. self.actionSheet.frame = self.view.bounds;
  22. }
  23. - (void)viewDidAppear:(BOOL)animated
  24. {
  25. [super viewDidAppear:animated];
  26. self.viewAlreadyAppear = YES;
  27. }
  28. - (void)viewWillLayoutSubviews
  29. {
  30. [super viewWillLayoutSubviews];
  31. self.actionSheet.frame = self.view.bounds;
  32. }
  33. - (BOOL)shouldAutorotate
  34. {
  35. // doesn't allow autorotation after the view did appear (rotation messes up a blurred background)
  36. return !self.viewAlreadyAppear;
  37. }
  38. #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
  39. - (NSUInteger)supportedInterfaceOrientations
  40. #else
  41. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  42. #endif
  43. {
  44. return UIInterfaceOrientationMaskAll;
  45. }
  46. -(void)didRotateDeviceChangeNotification:(NSNotification *)notification
  47. {
  48. [self.actionSheet dismissAnimated:NO];
  49. }
  50. - (UIStatusBarStyle)preferredStatusBarStyle
  51. {
  52. UIWindow *window = self.actionSheet.previousKeyWindow;
  53. if (!window) {
  54. window = [[UIApplication sharedApplication].windows firstObject];
  55. }
  56. return [[window ahk_viewControllerForStatusBarStyle] preferredStatusBarStyle];
  57. }
  58. - (BOOL)prefersStatusBarHidden
  59. {
  60. UIWindow *window = self.actionSheet.previousKeyWindow;
  61. if (!window) {
  62. window = [[UIApplication sharedApplication].windows firstObject];
  63. }
  64. return [[window ahk_viewControllerForStatusBarHidden] prefersStatusBarHidden];
  65. }
  66. @end