【发布时间】:2016-02-09 06:34:28
【问题描述】:
我正在创建一个仅支持纵向模式的应用程序。我不希望横向或纵向颠倒。我尝试了一些代码。这让我可以锁定纵向模式。
我正在使用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:
【问题讨论】:
-
检查这个也为我工作enter link description here
标签: ios iphone swift screen-orientation