gpt4 book ai didi

ios外部显示以编程方式

转载 作者:行者123 更新时间:2023-12-01 19:18:10 25 4
gpt4 key购买 nike

我正在尝试在我的 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 屏幕将正常工作,但当然我在模拟器屏幕上看不到任何内容。

有谁知道我应该怎么做?提前致谢!

最佳答案

我可以建议您尝试 GITHub 上的示例源代码 TVOut - https://github.com/JohnGoodstadt/TVOut .

它使用与您类似的代码,但打包在一个类中,您可以复制并从您自己的代码中调用它。

它应该可以解决您的显示问题。顺便说一句,我不会早在“didFinishLaunchingWithOptions”中执行您的代码,而是稍后在第一个 View Controller 中执行您的代码。

关于ios外部显示以编程方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11701058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com