3

So I am trying to start a project w/o Storyboards and I can't seem to figure out why the UIWindow is not passing autorotation commands to the root view controller. With storyboards, the autorotation works. If I create the window programmatically, autorotation does not work.

screenshot

This is how I instantiate the 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
}

Thanks!

chourobin
  • 4,004
  • 4
  • 35
  • 48

5 Answers5

8

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

Try removing the following line of code and any others to do with UIWindow:

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

Just need to remove above line from AppDelegate.m file.

jpd
  • 381
  • 1
  • 2
  • 13
2

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

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

I advice you to downgrade to XCode 6.0.1 and retry your app.

You can download it from here: Apple Downloads

valfer
  • 3,545
  • 2
  • 19
  • 24
1

Marked answer is to downgrade to XCode 6.0.1 - I do not recommend it.

1) If you do not use storyboards (Answer for this topic !!)

Go to -> Project Name -> Targets -> Project Name -> Deployment Info -> Main Interface -> Make it Empty


2) In case you use storyboards (not the main answer)

your AppDelegate should look like ...

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{
    return true
}
Jiří Zahálka
  • 8,070
  • 2
  • 21
  • 17
  • I have the same problem as the original poster, and the problem occurs even when the Main Interface is set as empty. – carbocation Aug 11 '15 at 18:33
0

Make sure you enable the device orientations in the project's General settings

in xcode 6.1, click your main project folder, General tab

Scroll down to Device Orientation, enable "Portrait", "Landscape Left", "Landscape Right"

See iOS 8.1 auto rotation for a picture of the Device Orientation settings

Community
  • 1
  • 1
anthonyliao
  • 1,314
  • 1
  • 8
  • 8
  • Thanks, I do have that set https://www.dropbox.com/s/9jh0ww0sfjkdzbz/Screenshot%202014-10-23%2019.04.34.png?dl=0 – chourobin Oct 23 '14 at 23:04
0

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 shared problem.

calql8edkos
  • 429
  • 4
  • 13