Using UIScreen to control a VGA display - doesn't seem to show UIWindow?

Hi

I am trying to use UIScreen to control a single screen using a VGA key on my iPad.

Here is what I got in the viewDidLoad root view controller:

//Code to detect if an external display is connected to the iPad. NSLog(@"Number of screens: %d", [[UIScreen screens]count]); //Now, if there 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; } 
+6
iphone ipad uiwindow vga
source share
6 answers

You need to run your window ...

  UIWindow *newwindow = [[UIWindow alloc] init]; 
+8
source share

[newwindow makeKeyAndVisible]; ?

+2
source share

I think your problem is externalDisplay. Create a viewcontroller outside of your code (maybe just add a new ViewController file and put the stuff in .xib) and try it to make sure that the viewcontroller works before you invoke it on an external screen. Here is your code with my suggested changes - [view of mainViewController] - this is the external connector you created.

 //Code to detect if an external display is connected to the iPad. NSLog(@"Number of screens: %d", [[UIScreen screens]count]); //Now, if there 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]; } 
+2
source share

Just write it down here if someone stumbles on this question. I could not get anything to appear on the second screen until I realized that the delegate of my application must save UIWindow. This one does not have a natural owner, so if you just do regular auto-advertising, the window will be released before it is displayed.

Hope this helps.

+2
source share

I uploaded a .xcodeproj sample to github.

I referred to this page basically.

Many thanks.:)

http://github.com/igaiga/iPadDisplayOutSample

+1
source share

It should be noted that the code provided on this page and on the github igaiga link is intended only for the “NOT CLONE” view, which is usually found on the iPad (or other device).

If you need to clone (aka Mirror) the view and update its contents, this link is more suitable: http://www.touchcentric.com/blog/archives/123

Hopefully this helps clarify the use cases for both sets of code for users who are just starting to integrate video output capabilities into existing applications.

0
source share

All Articles