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

萝らか妹 提交于 2021-02-08 11:50:44

问题


When running a simple proof-of-concept iPhone app on my phone (iOS 13.1.2), it doesn't rotate upside down. It will rotate to either of the landscape orientations just fine, but not upside down. One strange thing is that there's also a UITextEffects window whose view controllers get supportedInterfaceOrientations called on them (and they return .allButUpsideDown, which matches with the observed behavior). The project is here, but I'll show all of the code inline.

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 (excerpt):

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

回答1:


This is on purpose, the newer iPhones without Touch Id doesn't have the Upside Down capability. If you run your example on iPhone 8, it rotates as it should.

In https://forums.developer.apple.com/message/268015, an Apple staffer says:

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

And the official Apple documentation says:

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.

Also, see the 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.



来源:https://stackoverflow.com/questions/58328275/app-rotates-to-landscape-and-portrait-but-wont-rotate-upside-down

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!