Domanda

Ciao,

Sto cercando di utilizzare UIScreen per guidare uno schermo separato con il dongle VGA sul mio iPad.

Ecco quello che ho nella mia viewDidLoad radice vista del controllore:

//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;
 }
È stato utile?

Soluzione

È necessario inizializzare la finestra ...

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

Altri suggerimenti

[newwindow makeKeyAndVisible];?

Credo che il problema è l'externalDisplay. Creare un viewcontroller fuori il codice (magari fare un sufficiente aggiungere nuovo file ViewController e roba mettere in .xib) e provarlo per assicurarsi che viewcontroller sta lavorando prima di chiamare al monitor esterno. Ecco il codice con i miei cambiamenti suggeriti -. [Visualizza mainViewController] è il viewcontroller si è creato al di fuori

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

Basta registrare questo qui nel caso qualcuno inciampa su questa questione. Non ero in grado di ottenere qualcosa di presentarsi sul secondo schermo fino a quando ho capito che la mia app delegato ha dovuto mantenere l'UIWindow. Non ha proprietaria naturale, quindi se lo farete un autorelease regolare, la finestra sarà rilasciato prima ancora di display.

La speranza che aiuta.

Ho caricato .xcodeproj campione in github.

I riferisce a questa pagina, soprattutto.

Grazie mille. :)

http://github.com/igaiga/iPadDisplayOutSample

Ha bisogno di essere ricordato che il codice fornito in questa pagina e sul link GitHub da igaiga è semplicemente lo scopo di "muovere" (NON CLONE) l'opinione che sarebbe normalmente sul iPad (o altro dispositivo).

Se avete bisogno di clone (aka Mirror) la vista e aggiorna i suoi contenuti questo link è più adatto: http://www.touchcentric.com/blog/archives/123

Spero che questo aiuta a chiarire i casi d'uso per entrambi i set di codice per gli utenti appena iniziando a integrare le funzionalità di uscita video in applicazioni esistenti.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top