【问题标题】:App rotates to landscape and portrait, but won't rotate upside down应用旋转为横向和纵向,但不会倒置旋转
【发布时间】:2019-10-11 04:04:11
【问题描述】:

在我的手机 (iOS 13.1.2) 上运行一个简单的概念验证 iPhone 应用程序时,它不会倒转。它会很好地旋转到任一横向方向,但不会倒置。一件奇怪的事情是,还有一个 UITextEffects 窗口,其视图控制器调用了supportedInterfaceOrientations(并且它们返回.allButUpsideDown,这与观察到的行为相匹配)。该项目是here,但我将内联显示所有代码。

AppDelegate.swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?

  func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return .all
  }

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let c = ViewController()
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = c
    window?.makeKeyAndVisible()
    return true
  }
}

ViewController.swift:

import UIKit

class ViewController: UIViewController {

  override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .all
  }

  override var shouldAutorotate: Bool {
    return true
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .purple

    let redView = UIView()
    redView.backgroundColor = .red
    redView.frame = CGRect(x: 20, y: 20, width: 100, height: 100)
    view.addSubview(redView)
  }
}

Info.plist(摘录):

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>

【问题讨论】:

    标签: ios autorotate


    【解决方案1】:

    这是故意的,没有 Touch Id 的新款 iPhone 不具备 Upside Down 功能。如果您在 iPhone 8 上运行您的示例,它会按应有的方式旋转。

    https://forums.developer.apple.com/message/268015,一位苹果员工说:

    “这是设计使然。我们将在未来的版本中更新文档以反映这一点。”

    而官方Apple documentation说:

    系统将视图控制器支持的方向与应用支持的方向(由 Info.plist 文件或应用代理的 application:supportedInterfaceOrientationsForWindow: 方法确定)和设备支持的方向相交以确定是否旋转。 例如,iPhone X 不支持 UIInterfaceOrientationPortraitUpsideDown 方向

    另外,请参阅Apple Visual Design Orientation

    仅在纵向模式下运行的应用应在用户将设备旋转 180 度时将其内容旋转 180 度 -iPhone X 除外,它不支持倒置纵向模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      • 2021-12-27
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多