Jim,在向主 UIWindow 添加子视图时,更改添加它们的顺序会影响这些视图如何受设备初始方向的影响。例如,在具有导航控制器(在代码中创建)和视图控制器(在 IB 中创建)的 App 中,无论初始方向如何,以下代码都将正确显示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window addSubview:navigationController.view];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
但是,当应用程序以横向模式启动时,以下代码将变得混乱(注意窗口中 addSubview 调用的顺序):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window addSubview:viewController.view];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
我会尝试更改添加子视图的顺序。希望这可以帮助!