IOS 8: Autorotation doesn't work without storyboarding

So, I'm trying to run a project without storyboard and I can't figure out why UIWindow is not passing autorotation commands to the root view controller. Autorotation works from the storyboard. If I create the window programmatically, autorotation doesn't work.

screenshot

This is how I instantiate a window in the App Delegate:

window = UIWindow(frame: UIScreen.mainScreen().bounds)
if let window = window {
    window.backgroundColor = UIColor.whiteColor()
    window.makeKeyAndVisible()

    let nc: SignInViewController = UIStoryboard(name: "Main", bundle: nil)
            .instantiateViewControllerWithIdentifier("SignInViewController") as SignInViewController
    window.rootViewController = nc
}

      

Thank!

+3


source to share


5 answers


The noted answer is to upgrade to XCode 6.0.1 - I don't recommend it.

1) If you are not using storyboards (answer this section !!)

Goto -> Project Name -> Objectives -> Project Name -> Deployment Information -> Main Interface -> Make It Empty




2) If you are using storyboards (not the main answer)

your AppDelegate should look like ...

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{
    return true
}

      

+1


source


Are you using storyboards? If so, you might have old code in your didFinishLaunchingWithOptions application.

Try to remove the following line of code and any others related to UIWindow:



self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen])];

Just remove the line above from the AppDelegate.m file.

+8


source


I think your code is correct and you are seeing one (of many) XCode 6.1 errors.

I tried a very simple 6.1 application using your code and I could experiment with the error. Then I downgraded to 6.0.1 and my app autorotation was perfect.

I advise you to upgrade to XCode 6.0.1 and try again.

You can download it here: Apple Download

+2


source


Make sure you have enabled device orientations in the General Settings project

in xcode 6.1, click main project folder, General tab

Scroll down to Device Orientation, turn on "Portrait", "Landscape left", "Landscape right"

See iOS 8.1 auto rotation for a picture of device orientation settings

0


source


I just solved the problem in my project. for me the solution was to remove the animation from the following code:
[self presentViewController: root animated: animated completion:^{ [AppDelegate singleton].window.rootViewController = root; }];

which is now just [AppDelegate singleton].window.rootViewController = root;

I don't know if this answers your question, but it solved my instance of what I think is a common problem.

0


source







All Articles