Orientation / rotation using storyboards on iOS 6

So ... I just spent all day on this, saw different posts and tried a bunch of things to make it work, no luck. Now I have returned this as simple as possible case, and it still does not work.

In this simple scenario, I have a storyboard containing only the UINavigationController and the only initial view controller: enter image description here

After seeing all the messages about changes to the automatic rotation methods in IOS 6, I created a subclass of UINavigationController and implemented the shouldAutorotate and supportedInterfaceOrientations methods both in this subclass and on the first view controller:

Navigation controller:

// NavController.h
#import <UIKit/UIKit.h>

@interface NavController : UINavigationController

@end

// NavController.m
#import "NavController.h"

@interface NavController ()

@end

@implementation NavController

- (BOOL) shouldAutorotate {
    return YES;
}

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

First controller

// FirstController.h
#import <UIKit/UIKit.h>

@interface FirstController : UIViewController

@end

// FirstController.m
#import "FirstController.h"

@interface FirstController ()

@end

@implementation FirstController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

Project settings indicate that all rotations should be supported: enter image description here

...! , :

enter image description here

enter image description here

..! ? ! , , , , !

+5
3

.... , HOURS , , , , .

- , , Xcode Info.plist !

, , Xcode (iPad):

 - Portrait (top home button)
 - Portrait (bottom home button)

, , :

 - Landscape (left home button)
 - Landscape (right home button)

enter image description here

, . !

.

+1

, UINavigationController. :

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

AppDelegate.

, ( UINavigationController),

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

.

    - (BOOL)shouldAutorotate

- (NSUInteger)supportedInterfaceOrientations

ViewControllers (, ), ViewController .

UINavigationController :

    - (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;
}

ViewControllers , - . :). , !

+11

Submit your AppDelegate->didFinishLaunchingWithOptionsmethod.

It should be like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    // Override point for customization after application launch.
//    self.window.backgroundColor = [UIColor whiteColor];
//    [self.window makeKeyAndVisible];
    return YES;
}
+1
source

All Articles