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

标签 ios autorotate

在我的手机 (iOS 13.1.2) 上运行简单的概念验证 iPhone 应用程序时,它不会颠倒旋转。它可以很好地旋转到任一横向方向,但不会颠倒。一件奇怪的事情是,还有一个 UITextEffects 窗口,其 View Controller 被调用 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>

最佳答案

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

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

"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.

关于ios - 应用程序旋转为横向和纵向,但不会颠倒旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58328275/

相关文章:

ios - 以编程方式旋转 UIViewController?

iPhone - gcdasyncsocket 委托(delegate) Didreceive 在其他 View 中不起作用

iOS 11 动画 gif 在 UIImageView 中显示

ios - 如何提取JSON数组?

iOS7 应用向后兼容 iOS5 关于唯一标识符

YouTube 嵌入式视频的 iOS 6.0+ 自动旋转

ios - 在 7.3/9/2+ Swift 中,设备旋转时如何禁用旋转动画?

ios - 获取 Alamofire jsonSerializationFailed 中的代码值

ios - 仅在纵向模式下强制 UINavigationController

ios6 - 改变 AVCaptureVideoPreviewLayer 方向的问题