【发布时间】:2016-06-14 16:02:04
【问题描述】:
我有一个应用程序,其中主要内容呈现在一个支持所有界面方向的窗口中,而一些内容呈现在另一个仅支持纵向的窗口中。这大部分都可以正常工作,除了当设备在显示纵向窗口时旋转到横向时,状态栏仍然旋转到横向(而内容保持纵向)。
即使全方向窗口被隐藏,即使它从未被设置为关键,也是如此。这是iOS中的错误吗?我认为关键窗口应该确定状态栏的方向。
这是一个演示问题的最小应用程序:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var allOrientationsWindow: UIWindow!
var portraitWindow: UIWindow!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.allOrientationsWindow = createOrientationWindow(.All)
self.allOrientationsWindow.hidden = true
self.portraitWindow = createOrientationWindow(.Portrait)
self.portraitWindow.makeKeyAndVisible()
return true
}
func createOrientationWindow(orientations: UIInterfaceOrientationMask) -> UIWindow {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
let viewController = OrientationsViewController(orientations: orientations)
window.rootViewController = viewController
viewController.view.backgroundColor = UIColor.whiteColor()
return window
}
}
class OrientationsViewController: UIViewController {
var supportedOrientations: UIInterfaceOrientationMask
init(orientations: UIInterfaceOrientationMask) {
self.supportedOrientations = orientations
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
let label = UILabel(frame: CGRect(x: 50, y: 50, width: 50, height: 50))
label.text = "Hello"
self.view.addSubview(label)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return self.supportedOrientations
}
override func prefersStatusBarHidden() -> Bool {
return false
}
}
这是输出:
【问题讨论】:
标签: ios screen-orientation uiwindow