UIScreen screen always returns 1 screen

I am trying to display an image on an Apple TV using Airplay without mirroring mode. But the [UIScreen screen] method always returns 1 screen (main screen) when mirroring is off. I want my snapshot to display the same way as the photo app (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! I am using Apple TV1 and iPad 2 (iOS 5.0.1)

+2
source share
1 answer

Well, this is a bit misleading. You must act as follows:

  • Playback mirroring must be enabled
  • 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 the mirroring and shows the new content.
  • You can add views or the root view controller, as in the main part of the application.

Here is 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]; 
+5
source

Source: https://habr.com/ru/post/906975/


All Articles