ios - 当我创建一个新的 UIWindow 时,iPad airplay 显示器显示黑屏

标签 ios iphone ipad airplay mirroring

[编辑] 我重新启动了 iPad,它解决了这个问题。我把它留在这里是因为堆栈溢出不鼓励删除问题

我在 iPad Air 2 上发生了一件奇怪的事情。使用 https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html 中提到的方法

我为通过 AirPlay 连接的辅助显示器创建了一个新的 UIWindow 对象。

- (void)checkForExistingScreenAndInitializeIfPresent {
   if ([[UIScreen screens] count] > 1)
   {
    // Get the screen object that represents the external display.
    UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
    // Get the screen's bounds so that you can create a window of the correct size.
    CGRect screenBounds = secondScreen.bounds;

    self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
    self.secondWindow.screen = secondScreen;

    NSLog(@"Show external window");
    // Set up initial content to display...
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]];
    UIViewController *controller = [storyboard instantiateInitialViewController];
    self.secondWindow.rootViewController = controller;
    // Show the window.
    self.secondWindow.hidden = NO;
   }

当我在 iPhone 5s 上运行此代码时,该代码完美运行并且已初始化辅助窗口。但是,当我在 iPad Air 2 上从 Xcode 运行这段代码时,我只看到黑屏。如果该应用程序未通过 Xcode 运行,则该应用程序会在 iPad 上启动,但在 AirPlay 显示屏上它只会显示主屏幕,并突出显示应用程序图标。音频仍通过 AirPlay 路由。

如有任何帮助,我们将不胜感激。

最佳答案

通常我们会像这样更改我们的 UIWindow 颜色:

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];

您可以将 self.secondWindow 颜色设置为:

secondWindow.backgroundColor = [UIColor whiteColor];

关于ios - 当我创建一个新的 UIWindow 时,iPad airplay 显示器显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35269955/

相关文章:

iphone - 在 CoreAnimation 期间重置 UIScrollView contentOffset

ios - 应用程序与状态栏相遇的 iPad 圆角半径

objective-c - iPad - 我应该如何分发离线 Web 内容以供应用程序中的 UIWebView 使用?

ios - 仅加载包含资源的 bundle 时出现 "Cannot find executable for CFBundle"

iOS 拉伸(stretch)以适应所有屏幕尺寸?

ios - iPhone 应用程序图标背景颜色更改

iPhone 4 对比。 4s wifi数据上传速度差异

ios - 防止 iOS 配置文件应用程序过期

java - Java APNS 证书的正确格式是什么?

ios - Swift 中的 CoreWLAN