我正在尝试在我的 iOS 应用程序上支持外部显示而不使用任何 .xib 文件。
现在我的代码包含这个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if ([[UIScreen screens] count] > 1){
externalScreen = [[UIScreen screens] objectAtIndex:1];
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:0];
externalScreen.currentMode = current;
externalWindow = [[UIWindow alloc] initWithFrame:[externalScreen bounds]];
externalWindow.screen = externalScreen;
externalWindow.clipsToBounds = YES;
extController = [[ExternalController alloc] init];
[externalWindow addSubview:extController.view];
[externalWindow makeKeyAndVisible];
}
self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];
mainController = [[ViewController alloc] init];
[self.window addSubview:mainController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
}
当我运行它时,TV Out 屏幕将立即关闭。如果我评论这一行:
//self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];
TV Out 屏幕将正常工作,但当然我在模拟器屏幕上看不到任何内容。
有谁知道我应该怎么做?提前致谢!