Marino Faggiana 7 年之前
父節點
當前提交
d5f3f291a5
共有 1 個文件被更改,包括 27 次插入2 次删除
  1. 27 2
      iOSClient/Library/AHKActionSheet/AHKActionSheetViewController.m

+ 27 - 2
iOSClient/Library/AHKActionSheet/AHKActionSheetViewController.m

@@ -10,7 +10,10 @@
 #import "AHKActionSheet.h"
 
 @interface AHKActionSheetViewController ()
+
 @property (nonatomic) BOOL viewAlreadyAppear;
+@property (nonatomic) UIDeviceOrientation storeOrientation;
+
 @end
 
 @implementation AHKActionSheetViewController
@@ -22,7 +25,8 @@
     [super viewDidLoad];
 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotateDeviceChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
-    
+    self.storeOrientation = [[UIDevice currentDevice] orientation];
+
     [self.view addSubview:self.actionSheet];
     self.actionSheet.frame = self.view.bounds;
 }
@@ -34,6 +38,14 @@
     self.viewAlreadyAppear = YES;
 }
 
+- (void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+
 - (void)viewWillLayoutSubviews
 {
     [super viewWillLayoutSubviews];
@@ -58,7 +70,20 @@
 
 -(void)didRotateDeviceChangeNotification:(NSNotification *)notification
 {
-    [self.actionSheet dismissAnimated:NO];
+    UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
+    
+    // Ignore changes in device orientation if unknown, face up, or face down.
+    if (!UIDeviceOrientationIsValidInterfaceOrientation(currentOrientation)) {
+        return;
+    }
+    
+    //BOOL isLandscape = UIDeviceOrientationIsLandscape(currentOrientation);
+    //BOOL isPortrait = UIDeviceOrientationIsPortrait(currentOrientation);
+    
+    if (currentOrientation != self.storeOrientation) {
+        [self.actionSheet dismissAnimated:NO];
+        self.storeOrientation = currentOrientation;
+    }
 }
 
 @end