我有一个可以在应用程序中的任何位置呈现的 ViewController。我用这段代码 UIApplication.sharedApplication().keyWindow?.rootViewController?.presentedViewController?.presentViewController
来呈现它。所以我想禁用方向,只支持纵向。我尝试了很多解决方案,实现了shouldAutorotate/supportedInterfaceOrientations/preferredInterfaceOrientationForPresentation,但没有任何帮助。有人遇到过这个问题吗?
最佳答案
你在viewDidLoad中尝试过这个吗?
viewDidLoad() {
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
shouldAutorotate()
}
关于ios - 如何禁用 UIApplication.keyWindow() 呈现的 ViewController 上的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35847115/