gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:51:05 25 4
gpt4 key购买 nike

在我的手机 (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com