UIScreen screens always return 1 screen

孤街醉人 提交于 2019-12-08 03:08:13

问题


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.

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


回答1:


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

  • 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

Here's the code:

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


来源:https://stackoverflow.com/questions/11391902/uiscreen-screens-always-return-1-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!