【问题标题】:iPad airplay display shows black screen when I create a new UIWindow当我创建一个新的 UIWindow 时,iPad 播放显示器显示黑屏
【发布时间】:2016-05-18 03:12:58
【问题描述】:

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

任何帮助将不胜感激。

【问题讨论】:

  • 这里有一个疯狂的猜测,但情节提要中是否有您尝试加载的“仅限 iPhone”的内容?这可以解释为什么它不显示在 iPad 上。
  • @Ermiar 你不会相信的。在数小时无法弄清楚之后,我重新启动了 iPad。奇迹般地,它奏效了!
  • 哈哈好吧!在这种情况下,我不知道您是需要自己回答问题还是直接关闭它。无论如何,很高兴你找到了解决方案。
  • @Ermiar 我试图删除它,但我似乎找不到选项
  • 你的帖子下其他人旁边没有“删除”按钮吗?

标签: ios iphone ipad airplay mirroring


【解决方案1】:

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

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

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

secondWindow.backgroundColor = [UIColor whiteColor];

【讨论】:

    【解决方案2】:

    这是一个荒谬的案例,它的解决方案同样荒谬。我重新启动了 iPad,问题就消失了。

    【讨论】:

    • 我在 iPad 2 中遇到了同样的问题。就我而言,有时它经常发生。您找到任何理由或更好的解决方案了吗?
    • 不,我很抱歉@Deepak,它只发生在我身上一次,它消失后再也没有回来。
    • 感谢@Matt,对不起,我的设备不是 iPad 2,而是 iPad 3,3。设备信息-: 型号-: iPad Wi-Fi + 4G (LTE/GSM) - iPad3,3 iOS-: 9.3.1 (13E238)
    猜你喜欢
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多