iOS 8 : Autorotation is not working without storyboard

标签 ios iphone swift

所以我试图开始一个没有 Storyboard的项目,但我似乎无法弄清楚为什么 UIWindow 没有将自动旋转命令传递给 Root View Controller 。使用 Storyboard,自转有效。如果我以编程方式创建窗口,则自动旋转不起作用。

screenshot

这就是我在 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/

相关文章:

ios - 我的 UICollectionViewCell 项为零?

ios - 如何修复 "' NSInvalidArgumentException',原因: '-[__NSCFNumber caseInsensitiveCompare:]: unrecognised selector sent to instance"?

ios - iPad 应用程序左右两侧的空格

iphone - iPhone 上的 TRACE 日志记录

iphone - 如何获取iPhone中正在下载的zip文件名

ios - 为 Storyboard本地化添加评论

ios - Tabbar 自动布局问题

ios - UITableView 单元格行为不当,显示没有披露等

c++ - Xcode 7 不使用 C++ 框架构建项目

ios - 如何在UIView上获得长按时间