UIScreen屏幕始终返回1个屏幕 [英] UIScreen screens always return 1 screen

查看:200
本文介绍了UIScreen屏幕始终返回1个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在不带镜像模式的Airplay上的Apple TV上显示图片.但是,[UIScreen screens]方法在镜像关闭时总是返回1个屏幕(主屏幕). 我希望我的图片显示与照片"应用程序相同(无需镜像的Airplay).

I'm trying to display a picture on Apple TV with Airplay without mirroring mode. But [UIScreen screens] method always return 1 screen (main screen) when mirroring is OFF. I want my picture display same as Photo application (Airplay without mirroring).

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

我使用了它们,但是它们仅在镜像"处于启用"状态时起作用.

I used them, but they only work when Mirroring is ON.

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

Please help me. Thanks so much! I'm using Apple TV1 and iPad 2 (iOS 5.0.1)

推荐答案

嗯,确实有些误导.您应该按照以下步骤操作:

Well, it's a bit misleading, indeed. You should proceed as follows:

  • Airplay镜像选项应为开
  • 然后,您创建一个新的UIWindow并将其附加到第二个屏幕
  • 将makeKeyAndVisible发送到此新的UIWindow后,它将覆盖镜像并显示新内容.
  • 您可以在应用程序的主要部分中添加视图或根视图控制器
  • Airplay mirroring option should be ON
  • then, you create a new UIWindow and attach it to the second screen
  • as soon as you send makeKeyAndVisible to this new UIWindow, it overrides mirroring and shows new content.
  • You may add views or a root view controller as in the main part of application

代码如下:

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];

这篇关于UIScreen屏幕始终返回1个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆