如何在纵向模式下支持iPad的180度变体?

时间:2016-11-27 09:41:37

标签: ios swift xcode ipad

我正在设计一个通用应用程序,我喜欢只支持iPhone和iPad的肖像。但我需要iPad来支持常规和颠倒的纵向方向。

所以我在info.plist Portrait (top home button)Portrait (bottom home button).

中为iPhone和iPad设置了支持的界面方向

关注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度。我哪里错了?

2 个答案:

答案 0 :(得分:0)

您没有提及如何为项目配置部署信息。默认情况下,'颠倒'对于Universal项目,未选中该选项,您需要选择此选项以获得所需的方向

Xcode Deployment Info

答案 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
}