简体   繁体   English

带有UISplitViewController的UIWindow子类不会旋转

[英]UIWindow subclass with UISplitViewController does not rotate

Very easy problem to reproduce. 重现非常简单的问题。 Create a new Master/Detail Application iOS project, and change the AppDelegate to this: 创建一个新的Master / Detail Application iOS项目,并将AppDelegate更改为此:

import UIKit

class WindowSubclass: UIWindow { }

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

//    var window: UIWindow?
    var window: WindowSubclass? = { WindowSubclass(frame: UIScreen.mainScreen().bounds) }()

Run on iPad simulator/device and start rotating. 在iPad模拟器/设备上运行,然后开始旋转。 If the device was in portrait mode when the application was launched, it'll rotate fine. 如果启动应用程序时设备处于纵向模式,它将正常旋转。 If the application launched in landscape mode, it'll quickly get messed up. 如果应用程序以横向模式启动,它将很快陷入混乱。

iPad模拟器显示了不正确的旋转视图

I suspect my problem is in the getter for the window property, but I'm not sure how to resolve it. 我怀疑我的问题出在window属性的吸气剂中,但是我不确定如何解决它。 The line I used seems to be the canonical way of doing it. 我使用的直线似乎是规范的做法。

Based on answers to similar questions, I have ensured that the window's rootViewController is set to the UISplitViewController and the split view controller's shouldAutorotate() returns true , so that shouldn't be the issue. 基于类似问题的答案,我确保将窗口的rootViewController设置为UISplitViewController ,并且拆分视图控制器的shouldAutorotate()返回true ,所以这不应该成为问题。

Here's a 'maybe' solution. 这是一个“也许”的解决方案。

It seems that when the window property is accessed, and the WindowSubclass instantiated, the screen doesn't really know what orientation it is. 似乎在访问window属性并实例化WindowSubclass ,屏幕并不真正知道其方向。

If you add window!.frame = UIScreen.mainScreen().bounds in application(didFinishLaunchingWithOptions:) then it sorts itself out. 如果在application(didFinishLaunchingWithOptions:)添加window!.frame = UIScreen.mainScreen().bounds ,那么它将自行进行排序。

I think the reason this is happening is because it's the UIViewController which launches the app. 我认为发生这种情况的原因是因为UIViewController启动了应用程序。 On all other UIViewControllers , my subclass UIWindow rotates fine when I set its rootViewController as the UIViewController that it's being presented on. 在所有其他UIViewControllers ,我的子类UIWindow当我设置它的旋转精细rootViewController作为UIViewController ,它的呈现上。 I'm not sure if this is the intended behavior for some reason or if it's a bug in iOS. 我不确定这是出于某种原因的预期行为,还是iOS中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM