应用程序旋转为横向和纵向,但不会颠倒旋转

App rotates to landscape and portrait, but won't rotate upside down

当我的 phone (iOS 13.1.2) 上有一个简单的概念验证 iPhone 应用程序时,它不会颠倒旋转。它会很好地旋转到任一横向方向,但不会颠倒。一件奇怪的事情是还有一个 UITextEffects window,其视图控制器得到 supportedInterfaceOrientations 调用(它们 return .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>

这是故意的,没有 Touch Id 的较新 iPhones 没有颠倒功能。如果您 运行 您在 iPhone 8 上的示例,它会按原样旋转。

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

"It is by design. We're getting documentation updated in a future release to reflect that."

官方Apple documentation说:

The system intersects the view controller's supported orientations with the app's supported orientations (as determined by the Info.plist file or the app delegate's application:supportedInterfaceOrientationsForWindow: method) and the device's supported orientations to determine whether to rotate. For example, the UIInterfaceOrientationPortraitUpsideDown orientation is not supported on iPhone X.

另外,请参阅 Apple Visual Design Orientation

An app that runs only in portrait mode should rotate its content 180 degrees when the user rotates the device 180 degrees—except on iPhone X, which doesn’t support upside-down portrait mode.