Pergunta

Olá,

Estou tentando usar o UISCREEN para dirigir uma tela separada com o dongle VGA no meu iPad.

Aqui está o que eu tenho no meu ViewDidload do controlador de View ROOT:

//Code to detect if an external display is connected to the iPad.
 NSLog(@"Number of screens: %d", [[UIScreen screens]count]);

 //Now, if there's an external screen, we need to find its modes, itereate through them and find the highest one. Once we have that mode, break out, and set the UIWindow.

 if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
 {
  CGSize max;
  UIScreenMode *maxScreenMode;
  for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
  {
   UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
   if(current.size.width > max.width);
   {
    max = current.size;
    maxScreenMode = current;
   }
  }
  //Now we have the highest mode. Turn the external display to use that mode.
  UIScreen *external = [[UIScreen screens] objectAtIndex:1];
  external.currentMode = maxScreenMode;
  //Boom! Now the external display is set to the proper mode. We need to now set the screen of a new UIWindow to the external screen
  external_disp = [externalDisplay alloc];
  external_disp.drawImage = drawViewController.drawImage;
  UIWindow *newwindow = [UIWindow alloc];
  [newwindow addSubview:external_disp.view];
  newwindow.screen = external;
 }
Foi útil?

Solução

Você precisa iniciar sua janela ...

 UIWindow *newwindow = [[UIWindow alloc] init];

Outras dicas

[newwindow makeKeyAndVisible];?

Eu acho que seu problema é o ExternalDisplay. Crie um ViewController fora do seu código (talvez faça um novo novo arquivo ViewController e coloque as coisas no .xib) e experimente -o para garantir que o ViewController esteja funcionando antes de chamá -lo para o visor externo. Aqui está o seu código com minhas alterações sugeridas - [MainViewController View] é o ViewController que você criou fora.

//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);

//Now, if there's an external screen, we need to find its modes, iterate
//through them and find the highest one. Once we have that mode, break out,
//and set the UIWindow.

if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected
                                  //to the device
{
 CGSize max;
 UIScreenMode *maxScreenMode;
 for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
 {
  UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
  if(current.size.width > max.width);
  {
   max = current.size;
   maxScreenMode = current;
  }
 }
 //Now we have the highest mode. Turn the external display to use that mode.
 UIScreen *external = [[UIScreen screens] objectAtIndex:1];
 external.currentMode = maxScreenMode;
 //Boom! Now the external display is set to the proper mode. We need to now
 //set the screen of a new UIWindow to the external screen

 UIWindow *newwindow = [UIWindow alloc];

 [newwindow addSubview:[mainViewController view]];
 newwindow.screen = external;

 [newwindow makeKeyAndVisible];
 [newwindow setHidden:NO];
}

Apenas gravando isso aqui, caso alguém tropeça nessa pergunta. Não consegui que algo apareça na segunda tela até perceber que meu delegado de aplicativo tinha que reter a UIWindow. Ele não possui proprietário natural; portanto, se você apenas fizer um autorlease regular, a janela será lançada antes de exibir.

Espero que ajude.

Eu carreguei a amostra .xcodeproj no github.

Referi -me principalmente a esta página.

Muito obrigado. :)

http://github.com/igaiga/ipaddisplayoutsample

É preciso mencionar que o código fornecido nesta página e no link do github por Igaiga se destina apenas a "mover" (não clonar) a visualização que normalmente estaria no iPad (ou outro dispositivo).

Se você precisar clonar (também conhecido como espelho) a vista e atualizar seu conteúdo, este link é mais adequado: http://www.touchcentric.com/blog/archives/123

Espero que isso ajude a esclarecer os casos de uso para os dois conjuntos de código para os usuários que começam a integrar recursos de vídeo em aplicativos existentes.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top