【发布时间】:2017-03-07 12:09:41
【问题描述】:
在应用代理中:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.landscape.rawValue)
}
在我的视图控制器(MainViewController)中我添加了
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
supportedInterfaceOrientations()
preferredInterfaceOrientationForPresentation()
// Do any additional setup after loading the view.
}
private func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
private func shouldAutorotate() -> Bool {
return true
}
private func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
// Only allow Portrait
return UIInterfaceOrientation.portrait
}
这是我想要在纵向模式下工作的应用程序中唯一的控制器。除了横向模式下的一切。
但是我尝试了很多东西仍然无法理解为什么它不起作用。
提前致谢。对不起,我是 swift 的菜鸟。
【问题讨论】:
标签: uiviewcontroller swift3 orientation landscape-portrait