Procházet zdrojové kódy

Improve rotation behavior of the toolbar.

If the view underneath wants to rotate, rotate with it. If not, stay stationary.
Ryan Olson před 12 roky
rodič
revize
0c53ef9919

+ 16 - 4
Classes/Explorer Toolbar/FLEXExplorerViewController.m

@@ -118,7 +118,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 // In general, our window shouldn't be the key window when this view controller is asked about the status bar.
 // However, we guard against infinite recursion and provide a reasonable default for status bar behavior in case our window is the keyWindow.
 
-- (UIViewController *)viewControllerForStatusBarProperties
+- (UIViewController *)viewControllerForStatusBarAndOrientationProperties
 {
     UIViewController *viewControllerToAsk = [[[UIApplication sharedApplication] keyWindow] rootViewController];
     
@@ -134,7 +134,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 - (UIStatusBarStyle)preferredStatusBarStyle
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     UIStatusBarStyle preferredStyle = UIStatusBarStyleDefault;
     if (viewControllerToAsk != self) {
         preferredStyle = [viewControllerToAsk preferredStatusBarStyle];
@@ -144,7 +144,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     UIStatusBarAnimation preferredAnimation = UIStatusBarAnimationFade;
     if (viewControllerToAsk != self) {
         preferredAnimation = [viewControllerToAsk preferredStatusBarUpdateAnimation];
@@ -154,7 +154,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 - (BOOL)prefersStatusBarHidden
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     BOOL prefersHidden = NO;
     if (viewControllerToAsk != self) {
         prefersHidden = [viewControllerToAsk prefersStatusBarHidden];
@@ -163,6 +163,18 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 }
 
 
+#pragma mark - Rotation
+
+- (NSUInteger)supportedInterfaceOrientations
+{
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
+    NSUInteger supportedOrientations = [FLEXUtility infoPlistSupportedInterfaceOrientationsMask];
+    if (viewControllerToAsk != self) {
+        supportedOrientations = [viewControllerToAsk supportedInterfaceOrientations];
+    }
+    return supportedOrientations;
+}
+
 #pragma mark - Setter Overrides
 
 - (void)setSelectedView:(UIView *)selectedView

+ 1 - 0
Classes/Utility/FLEXUtility.h

@@ -23,5 +23,6 @@
 + (UIFont *)defaultFontOfSize:(CGFloat)size;
 + (UIFont *)defaultTableViewCellLabelFont;
 + (NSString *)stringByEscapingHTMLEntitiesInString:(NSString *)originalString;
++ (NSUInteger)infoPlistSupportedInterfaceOrientationsMask;
 
 @end

+ 19 - 0
Classes/Utility/FLEXUtility.m

@@ -146,4 +146,23 @@
     return [mutableString copy];
 }
 
++ (NSUInteger)infoPlistSupportedInterfaceOrientationsMask
+{
+    NSArray *supportedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
+    NSUInteger supportedOrientationsMask = 0;
+    if ([supportedOrientations containsObject:@"UIInterfaceOrientationPortrait"]) {
+        supportedOrientationsMask |= UIInterfaceOrientationPortrait;
+    }
+    if ([supportedOrientations containsObject:@"UIInterfaceOrientationMaskLandscapeRight"]) {
+        supportedOrientationsMask |= UIInterfaceOrientationMaskLandscapeRight;
+    }
+    if ([supportedOrientations containsObject:@"UIInterfaceOrientationMaskPortraitUpsideDown"]) {
+        supportedOrientationsMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
+    }
+    if ([supportedOrientations containsObject:@"UIInterfaceOrientationLandscapeLeft"]) {
+        supportedOrientationsMask |= UIInterfaceOrientationLandscapeLeft;
+    }
+    return supportedOrientationsMask;
+}
+
 @end