Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带有UISplitViewController的UIWindow子类不旋转_Ios - Fatal编程技术网

Ios 带有UISplitViewController的UIWindow子类不旋转

Ios 带有UISplitViewController的UIWindow子类不旋转,ios,Ios,很容易复制的问题。创建新的主/详细应用程序iOS项目,并将AppDelegate更改为: import UIKit class WindowSubclass: UIWindow { } @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { // var window: UIWindow? var window: Wind

很容易复制的问题。创建新的主/详细应用程序iOS项目,并将AppDelegate更改为:

import UIKit

class WindowSubclass: UIWindow { }

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

//    var window: UIWindow?
    var window: WindowSubclass? = { WindowSubclass(frame: UIScreen.mainScreen().bounds) }()
在iPad模拟器/设备上运行并开始旋转。如果应用程序启动时设备处于纵向模式,它将正常旋转。如果应用程序以横向模式启动,它将很快陷入混乱

我怀疑我的问题出在
窗口的getter中,但我不确定如何解决它。我用的这句话似乎是做这件事的标准方式


根据对类似问题的回答,我已确保窗口的
rootViewController
设置为
UISplitViewController
,并且分割视图控制器的
应该自动旋转()
返回
true
,因此这不应该是问题。

这里有一个“可能”的解决方案

当访问
窗口
属性,并实例化
窗口子类
时,屏幕似乎不知道它是什么方向


如果添加
窗口!。frame=UIScreen.mainScreen().bounds
应用程序中(didfishlaunchingwithoptions:)
然后它会自己整理出来。

我认为发生这种情况的原因是因为启动应用程序的是
UIViewController
。在所有其他
UIViewController
上,当我将其
rootViewController
设置为显示它的
UIViewController
时,我的子类
UIWindow
旋转良好。我不确定这是出于某种原因的预期行为,还是iOS中的一个bug