Pregunta

HI allí,

Estoy tratando de utilizar UIScreen para conducir una pantalla separada con el dongle VGA en mi iPad.

Esto es lo que tengo en mi viewDidLoad raíz del controlador de vista:

//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;
 }
¿Fue útil?

Solución

Es necesario para inicializar la ventana ...

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

Otros consejos

[newwindow makeKeyAndVisible];?

Creo que su problema es la externalDisplay. Crear un viewcontroller fuera de su código (tal vez hacer un nuevo archivo sólo tiene que añadir ViewController y cosas por el puesto en la .xib) y probarlo para asegurarse de que está trabajando viewcontroller antes de llamar en la pantalla externa. Aquí está el código con mis cambios sugeridos -. [Ver mainViewController] es la que ha creado viewcontroller fuera

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

Sólo registrar esta aquí por si tropieza cualquier persona en esta pregunta. Yo no era capaz de conseguir cualquier cosa para aparecer en la segunda pantalla hasta que me di cuenta de que mi aplicación delegado tuvo que retener el UIWindow. Que no tiene dueño natural, por lo que si usted acaba de hacer un autorelease regular, la ventana se dará a conocer antes incluso de pantallas.

Espero que ayude.

He subido .xcodeproj muestra en GitHub.

I referido a esta página, principalmente.

Muchas gracias. :)

http://github.com/igaiga/iPadDisplayOutSample

Es necesario mencionar que el código proporcionado en esta página y en el enlace github por igaiga es meramente la intención de "movimiento" (NO COPIA) la opinión de que sería normalmente en el IPAD (u otro dispositivo).

Si necesita clon (también conocido como espejo) de la vista y actualizar su contenido este enlace es más adecuado: http://www.touchcentric.com/blog/archives/123

Espero que esto ayude a aclarar los casos de uso para ambos conjuntos de código para los usuarios que están empezando a integrar capacidades de salida de vídeo en aplicaciones existentes.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top