【发布时间】:2019-10-11 04:04:11
【问题描述】:
在我的手机 (iOS 13.1.2) 上运行一个简单的概念验证 iPhone 应用程序时,它不会倒转。它会很好地旋转到任一横向方向,但不会倒置。一件奇怪的事情是,还有一个 UITextEffects 窗口,其视图控制器调用了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>
【问题讨论】:
标签: ios autorotate