25

i added the new methods to my code like described at apples iOS 6 Documentations but on the iPhone 5 the App doesn't rotate to upside down. Only the to landscape Ways.

Here my Code from the rootViewController:

- (NSUInteger)supportedInterfaceOrientations{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate{
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return YES;
}

i tryed also "UIInterfaceOrientationMaskAll" but no changes. The Strange is, my iPhone 4 with iOS6 does totate o upside down with the same code.

Any Ideas?

2

5 Answers 5

61

IOS 6 uses default Orientation UIInterfaceOrientationMaskAllfor iPad and UIInterfaceOrientationMaskAllButUpsideDownfor iPhone. If you want your ViewControllers on the iPhone to rotate to ALL orientations including UpsideDown you must add the iOS 6 method:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

to all view controllers. If you've done this and it is not working then I am betting your using a TabViewController or NavigationController where some of the views are NOT returning this. All ViewControllers must return this for ANY of them to support it.

Alternatively you can add a Category to the UITabViewController or NavigationController class that is your rootViewController and override that method. You do that like so:

@interface UITabBarController (RotationAll)
    -(NSUInteger)supportedInterfaceOrientations;
@end

@implementation UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
@end

Also these are the currently recommended approaches now being discussed in Apple Developer Forums with Apple staff saying earlier documentation that discouraged sub classing of UINavigationController is out of date, and as of iOS 6 it is ok to do that.

6
  • +1, solved my problem at, but: needed to remove from phone the previos build too!!!
    – user529543
    Dec 10, 2012 at 13:33
  • Maybe it is worth to report to Apple, it is confusing that you can set All orientations in the XML (info.plist) but it is overwrite. Aug 19, 2013 at 21:22
  • Go for it dude. Report it as a bug if you think it's an issue. Bit late though, iOS7 just about done cooking. Doubt anyone at 1 infinite will pay much attention to iOS 6 complaints :) Aug 20, 2013 at 22:49
  • Yeah but so many other things changed about handling orientation in iOS7. Nov 14, 2013 at 16:12
  • The key to this is to determine which view controller is at the root. In my case it was the UINavigationController used by the nib. An alternative to using a category would be to make a subclass and set the nib to use that subclass.
    – ThomasW
    Apr 15, 2014 at 2:08
12

Thanks to Cliff Ribaudo really help full your answer for UITabbarController based project but in my case i am only using UINavigationController so i have modified your answer for UINavigationController categeory.

@interface UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end   


@implementation UINavigationController (RotationAll)
  -(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
  }
@end
1
  • For recent versions of Xcode you don't need the @interface, just having the @implementation works.
    – ThomasW
    Apr 15, 2014 at 1:53
0

Forgive the verbosity, but I think your answer is below.

I was having the same problem, but it was occurring on all IOS 6 devices including my iphone 4. Reading your question actually answered mine. I had removed this ages ago because it wasn't doing anything:

- (NSUInteger)supportedInterfaceOrientations{    
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown); }

and my code was working perfectly in prior ios releases. It appears this has become manditory in ios 6. But only for upsideDown. The other orientations were working fine.

So, thank you.

Back to your problem. Have you reviewed your project target to see if all "Supported Interface Orientations" are dark gray? I'm wondering if upside down is light gray, (ie, unchecked). I found in a quick test that on prior ios releases these are ignored too. As long as you return YES from shouldAutorotateToInterfaceOrientation it will support the orientations, but not in iOS 6.

Lastly, you have implemented shouldAutorotate, which I have not in my code. I think this defaults to Yes. And I think this just tells the os to try to rotate, but then you have to tell it which orientations you support with shouldAutorotateToInterfaceOrientation. But your snippet doesn't show that you've implemented shouldAutorotateToInterfaceOrientation. I would suggest implementing this as it tells the OS which orientations you support returning a simple YES means you support all.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

Hope this helps.

0

Default target settings is no upside-down orientation, so try this:

Go to Project file select your app target select "Summery" tab check that all orientation types pressed

Good luck :)

0

If you plan to enable or disable rotation for all view controllers you don't need to subclass UINavigationController. Instead use:

   -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

in your AppDelegate.

If you plan to support all orientations in your app but different orientations on PARENT View Controllers (UINavigationController stack for example) you should use

   -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

from AppDelegate in combination with the following methods in your PARENT View Controller.

    - (BOOL)shouldAutorotate

and

- (NSUInteger)supportedInterfaceOrientations

But if you plan to have different orientation settings in different CHILDREN ViewControllers in the same navigation stack (like me) you need to check the current ViewController in the navigation stack.

I've created the following in my UINavigationController subclass:

    - (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    int interfaceOrientation = 0;

    if (self.viewControllers.count > 0)
    {
        id viewController;
        DLog(@"%@", self.viewControllers);
        for (viewController in self.viewControllers)
        {
            if ([viewController isKindOfClass:([InitialUseViewController class])])
            {
                 interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
            }
            else if ([viewController isKindOfClass:([MainViewController class])])
            {
                 interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
            }
            else
            {
                 interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
            }
        }
    }
    return interfaceOrientation;
}

Since you cannot control anymore from children ViewControllers the rotation settings of presented view controller you must somehow intercept what view controller is currently in the navigation stack. So that's what I did :). Hope that helps !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.