2

我正在尝试在没有镜像模式的情况下使用 Airplay 在 Apple TV 上显示图片。但是当镜像关闭时,[UIScreen 屏幕] 方法总是返回 1 个屏幕(主屏幕)。我希望我的图片显示与照片应用程序相同(不带镜像的 Airplay)。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];

我使用了它们,但它们仅在镜像打开时才起作用。

请帮我。非常感谢!我正在使用 Apple TV1 和 iPad 2 (iOS 5.0.1)

4

1 回答 1

5

嗯,确实有点误导。您应该按以下步骤进行:

  • Airplay 镜像选项应该打开
  • 然后,您创建一个新的UIWindow并将其附加到第二个屏幕
  • 一旦您将 makeKeyAndVisible 发送到这个 new UIWindow,它就会覆盖镜像并显示新内容。
  • 您可以在应用程序的主要部分添加视图或根视图控制器

这是代码:

UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
self.secondWindow = [[UIWindow alloc] initWithFrame:secondScreen.bounds];
[self.secondWindow setScreen:secondScreen];
[self.secondWindow setBackgroundColor:[UIColor greenColor]];
[self.secondWindow makeKeyAndVisible];
于 2012-08-20T19:37:32.283 回答