我正在创建一个仅支持竖屏模式的应用程序。我不想要横屏或倒置的竖屏。我尝试了一些代码,可以让我锁定为竖屏模式。
我正在使用navigationcontroller和presentviewcontroller。现在我的问题是: 1. 如果我把设备倒置并打开我的应用程序,它会以倒置模式打开,这是错误的。 2. 我点击某个按钮进入presentviewcontroller后,它会返回到竖屏模式。
我希望所有的navigationcontroller和presentviewcontroller都在竖屏模式下
我的代码:
我在目标 -> 通用 -> 部署信息 -> 竖屏
中将设备方向设置为竖屏。
在我的appdelagate.swift中:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
在我的第一个视图控制器中,基本上是导航控制器的子视图。
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return [UIInterfaceOrientationMask.Portrait ]
}
编辑 1:
我还设置了StoryBoard -> ViewController -> Attribute Inspector -> Orientation -> Portrait
。
编辑 2: