【问题标题】:How to support 180 degree variant for iPad in portrait mode?如何在纵向模式下支持 iPad 的 180 度变体?
【发布时间】: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 度。我哪里错了?

【问题讨论】:

    标签: ios swift xcode ipad


    【解决方案1】:

    您没有提及如何为项目配置部署信息。默认情况下,通用项目的“倒置”选项未选中,您需要选择此选项以获得所需的方向

    【讨论】:

      【解决方案2】:

      我可以做到这一点

      在 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
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-23
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-22
        • 2015-01-01
        • 1970-01-01
        相关资源
        最近更新 更多