【发布时间】:2016-11-27 09:41:37
【问题描述】:
我正在设计一个通用应用程序,我希望只支持 iPhone 和 iPad 的纵向。但我需要 iPad 支持常规和倒置纵向。
所以我将info.plist 中的 iPhone 和 iPad 支持的界面方向设置为 Portrait (top home button) 和 Portrait (bottom home button).
关注AppDeleagte.swift
var shouldSupportAllOrientation = false
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if (shouldSupportAllOrientation == true){
return UIInterfaceOrientationMask.all
}
return UIInterfaceOrientationMask.portrait
}
关注ViewController.swift
override func viewWillAppear(_ animated: Bool) {
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.shouldSupportAllOrientation = false
let value = UIInterfaceOrientation.portraitUpsideDown.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
当我在模拟器中将我的 iPad 倒置旋转时,它仍然是倒置的,并且没有旋转 180 度。我哪里错了?
【问题讨论】: