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

cho*_*bin 3 iphone ios swift

所以我试图启动一个没有故事板的项目,我似乎无法弄清楚为什么UIWindow没有将自动旋转命令传递给根视图控制器.通过故事板,自动旋转起作用.如果我以编程方式创建窗口,则自动旋转不起作用.

截图

这是我在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
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

jpd*_*jpd 8

你在使用故事板吗?如果是这样,您的应用程序中可能有旧代码didFinishLaunchingWithOptions方法.

尝试删除以下代码行以及与UIWindow相关的任何其他代码:

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

只需要从AppDelegate.m文件中删除上面的行.