我正在设计一个通用应用程序,我喜欢只支持iPhone和iPad的肖像。但我需要iPad来支持常规和颠倒的纵向方向。
所以我在info.plist
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度。我哪里错了?
答案 0 :(得分:0)
答案 1 :(得分:0)
我可以通过
实现这一目标在AppDeleagte.swift中关注
var shouldSupportAllOrientation = false
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if (shouldSupportAllOrientation == true){
return UIInterfaceOrientationMask.all
}
return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown]
}
在ViewController.swift中跟随
override func viewWillAppear(_ animated: Bool) {
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.shouldSupportAllOrientation = false
}