Kaynağa Gözat

Improve rotation behavior of the toolbar.

If the view underneath wants to rotate, rotate with it. If not, stay stationary.
Ryan Olson 12 yıl önce
ebeveyn
işleme
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.
 // 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.
 // 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];
     UIViewController *viewControllerToAsk = [[[UIApplication sharedApplication] keyWindow] rootViewController];
     
     
@@ -134,7 +134,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 
 - (UIStatusBarStyle)preferredStatusBarStyle
 - (UIStatusBarStyle)preferredStatusBarStyle
 {
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     UIStatusBarStyle preferredStyle = UIStatusBarStyleDefault;
     UIStatusBarStyle preferredStyle = UIStatusBarStyleDefault;
     if (viewControllerToAsk != self) {
     if (viewControllerToAsk != self) {
         preferredStyle = [viewControllerToAsk preferredStatusBarStyle];
         preferredStyle = [viewControllerToAsk preferredStatusBarStyle];
@@ -144,7 +144,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 
 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
 {
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     UIStatusBarAnimation preferredAnimation = UIStatusBarAnimationFade;
     UIStatusBarAnimation preferredAnimation = UIStatusBarAnimationFade;
     if (viewControllerToAsk != self) {
     if (viewControllerToAsk != self) {
         preferredAnimation = [viewControllerToAsk preferredStatusBarUpdateAnimation];
         preferredAnimation = [viewControllerToAsk preferredStatusBarUpdateAnimation];
@@ -154,7 +154,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 
 
 - (BOOL)prefersStatusBarHidden
 - (BOOL)prefersStatusBarHidden
 {
 {
-    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarProperties];
+    UIViewController *viewControllerToAsk = [self viewControllerForStatusBarAndOrientationProperties];
     BOOL prefersHidden = NO;
     BOOL prefersHidden = NO;
     if (viewControllerToAsk != self) {
     if (viewControllerToAsk != self) {
         prefersHidden = [viewControllerToAsk prefersStatusBarHidden];
         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
 #pragma mark - Setter Overrides
 
 
 - (void)setSelectedView:(UIView *)selectedView
 - (void)setSelectedView:(UIView *)selectedView

+ 1 - 0
Classes/Utility/FLEXUtility.h

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

+ 19 - 0
Classes/Utility/FLEXUtility.m

@@ -146,4 +146,23 @@
     return [mutableString copy];
     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
 @end