why iPhone 5 doesn't rotate to upsideDown
Asked Answered
A

5

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?

Alvera answered 22/9, 2012 at 9:13 Comment(2)
Did you check the physical rotation switch? (just kidding)Krever
Look here .. https://mcmap.net/q/537956/-ios-8-upside-down-orientation-xcode-option-enabled-still-doesn-39-t-workRuyle
S
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.

Stark answered 6/10, 2012 at 9:55 Comment(6)
+1, solved my problem at, but: needed to remove from phone the previos build too!!!Millisecond
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.Planar
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 :)Stark
Yeah but so many other things changed about handling orientation in iOS7.Stark
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.Dufour
Note that the @interface is no longer needed, only the @implementation.Dufour
E
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
Exurbanite answered 26/4, 2013 at 10:2 Comment(1)
For recent versions of Xcode you don't need the @interface, just having the @implementation works.Dufour
N
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.

Nemhauser answered 25/9, 2012 at 20:5 Comment(0)
D
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 :)

Diazomethane answered 9/10, 2012 at 17:57 Comment(0)
H
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 !

Heterodox answered 20/1, 2013 at 0:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.