AHKActionSheetViewController.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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) UIDeviceOrientation 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:UIDeviceOrientationDidChangeNotification object:nil];
  20. self.storeOrientation = [[UIDevice currentDevice] orientation];
  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. UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
  55. // Ignore changes in device orientation if unknown, face up, or face down.
  56. if (!UIDeviceOrientationIsValidInterfaceOrientation(currentOrientation)) {
  57. return;
  58. }
  59. //BOOL isLandscape = UIDeviceOrientationIsLandscape(currentOrientation);
  60. //BOOL isPortrait = UIDeviceOrientationIsPortrait(currentOrientation);
  61. if (currentOrientation != self.storeOrientation) {
  62. [self.actionSheet dismissAnimated:NO];
  63. self.storeOrientation = currentOrientation;
  64. }
  65. }
  66. @end