所以我试图开始一个没有 Storyboard的项目,但我似乎无法弄清楚为什么 UIWindow 没有将自动旋转命令传递给 Root View Controller 。使用 Storyboard,自转有效。如果我以编程方式创建窗口,则自动旋转不起作用。
这就是我在 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
}
谢谢!
最佳答案
你在使用 Storyboard吗?如果是这样,您的应用程序 didFinishLaunchingWithOptions 方法中可能有旧代码。
尝试删除以下代码行和任何其他与 UIWindow 相关的代码:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
只需要从 AppDelegate.m 文件中删除上面的行。
关于iOS 8 : Autorotation is not working without storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26522056/