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. @interface AHKActionSheetViewController ()
  11. @property (nonatomic) BOOL viewAlreadyAppear;
  12. @property (nonatomic) UIInterfaceOrientation storeOrientation;
  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:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
  20. _storeOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  21. [self.view addSubview:self.actionSheet];
  22. self.actionSheet.frame = self.view.bounds;
  23. }
  24. - (void)viewDidAppear:(BOOL)animated
  25. {
  26. [super viewDidAppear:animated];
  27. self.viewAlreadyAppear = YES;
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated
  30. {
  31. [super viewWillDisappear:animated];
  32. [[NSNotificationCenter defaultCenter] removeObserver:self];
  33. }
  34. - (void)viewWillLayoutSubviews
  35. {
  36. [super viewWillLayoutSubviews];
  37. self.actionSheet.frame = self.view.bounds;
  38. }
  39. - (BOOL)shouldAutorotate
  40. {
  41. // doesn't allow autorotation after the view did appear (rotation messes up a blurred background)
  42. return !self.viewAlreadyAppear;
  43. }
  44. #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
  45. - (NSUInteger)supportedInterfaceOrientations
  46. #else
  47. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  48. #endif
  49. {
  50. return UIInterfaceOrientationMaskAll;
  51. }
  52. -(void)didRotateDeviceChangeNotification:(NSNotification *)notification
  53. {
  54. UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  55. if (currentOrientation != _storeOrientation) {
  56. [self.actionSheet dismissAnimated:NO];
  57. }
  58. _storeOrientation = currentOrientation;
  59. }
  60. @end