[编辑] 我重新启动了 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/