简体   繁体   English

iOS 8:没有故事板,自动旋转无法运行

[英]iOS 8: Autorotation is not working without storyboard

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. 所以我试图启动一个没有Storyboard的项目,我似乎无法弄清楚为什么UIWindow没有将自动旋转命令传递给根视图控制器。 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: 这是我在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! 谢谢!

Are you using storyboards? 你在使用故事板吗? If so, you may have old code in your application didFinishLaunchingWithOptions method. 如果是这样,您的应用程序中可能有旧代码didFinishLaunchingWithOptions方法。

Try removing the following line of code and any others to do with UIWindow: 尝试删除以下代码行以及与UIWindow相关的任何其他代码:

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

Just need to remove above line from AppDelegate.m file. 只需要从AppDelegate.m文件中删除上面的行。

I think your code is correct and you are seeing one (of many) bugs of XCode 6.1. 我认为您的代码是正确的,并且您正在看到XCode 6.1中的一个(很多)错误。

I tried a very simple app with 6.1 using your code and I could experiment the bug. 我使用你的代码尝试了一个非常简单的6.1应用程序,我可以试验这个bug。 Then I downgraded to 6.0.1 and the autorotation of my app was perfect. 然后我降级到6.0.1并且我的应用程序的自动旋转是完美的。

I advice you to downgrade to XCode 6.0.1 and retry your app. 我建议你降级到XCode 6.0.1并重试你的应用程序。

You can download it from here: Apple Downloads 您可以从此处下载Apple下载

Marked answer is to downgrade to XCode 6.0.1 - I do not recommend it. 标记的答案是降级到XCode 6.0.1 - 我不推荐它。

1) If you do not use storyboards (Answer for this topic !!) 1)如果您不使用故事板 (本主题的答案!!)

Go to -> Project Name -> Targets -> Project Name -> Deployment Info -> Main Interface -> Make it Empty 转到 - >项目名称 - >目标 - >项目名称 - >部署信息 - > 主界面 - >将其清空


2) In case you use storyboards (not the main answer) 2)万一你使用故事板 (不是主要答案)

your AppDelegate should look like ... 你的AppDelegate应该看起来像......

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

Make sure you enable the device orientations in the project's General settings 确保在项目的常规设置中启用设备方向

in xcode 6.1, click your main project folder, General tab 在xcode 6.1中,单击主项目文件夹,常规选项卡

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 有关“设备方向”设置的图片,请参阅iOS 8.1自动旋转

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; 现在只是[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. 我不知道这是否能回答你的问题,但它解决了我认为是共同问题的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM