我正在创建一个仅支持纵向模式的应用程序。我不希望风景或人像颠倒。我尝试了一些代码。这允许我锁定纵向模式。
我正在使用navigationcontroller和presentviewcontroller。现在我的问题是: 1.如果我将设备上下颠倒并打开我的应用程序,它会以颠倒模式打开,这是错误的。 2.我点击一些按钮,进入presentviewcontroller,返回纵向模式。
我希望所有的navigationcontroller和presentviewcontroller都处于纵向模式
我的代码:
我在Target -> General -> Deployment Info -> Portrait
在我的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: