在我的手机 (iOS 13.1.2) 上运行简单的概念验证 iPhone 应用程序时,它不会倒置旋转。它可以很好地旋转到任一横向方向,但不会颠倒。一件奇怪的事情是,还有一个 UITextEffects 窗口,其视图控制器被supportedInterfaceOrientations调用(并且它们返回.allButUpsideDown,这与观察到的行为相匹配)。该项目在这里,但我将展示所有内联代码。
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
}
}
Run Code Online (Sandbox Code Playgroud)
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)
}
}
Run Code Online (Sandbox Code Playgroud)
Info.plist(摘录):
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
Run Code Online (Sandbox Code Playgroud)
这是故意的,没有 Touch Id 的新款 iPhone 不具备颠倒功能。如果您在 iPhone 8 上运行示例,它会按应有的方式旋转。
\n\n在https://forums.developer.apple.com/message/268015中,一位 Apple 工作人员表示:
\n\n\n\n\n“这是设计使然。我们将在未来版本中更新文档以反映这一点。”
\n
苹果官方文档说:
\n\n\n\n\n系统将视图控制器支持的方向与应用程序支持的方向(由 Info.plist 文件或应用程序委托的 application:supportedInterfaceOrientationsForWindow: 方法确定)以及设备支持的方向相交判断是否旋转。例如,iPhone X 不支持 UIInterfaceOrientationPortraitUpsideDown 方向。
\n
另请参阅Apple 视觉设计方向:
\n\n\n\n仅在纵向模式下运行的应用程序应在用户将设备旋转 180 度时将其内容旋转 180 度\xe2\x80\x94,iPhone X 除外,\xe2\x80\x99 不支持颠倒纵向模式。
\n
| 归档时间: |
|
| 查看次数: |
1277 次 |
| 最近记录: |