问题
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