Created
September 7, 2010 23:08
-
-
Save jfricker/569309 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // External Monitor with View Controller | |
| // add this to you App Delegate subclass | |
| // In applicationDidFinishLaunching ... | |
| if ([UIScreen screens].count > 1) { | |
| [self attachViewToExt]; | |
| } | |
| // | |
| // extWindow is a retained property of your app delegate | |
| - (void)attachViewToExt { | |
| UIScreen *extScreen = [[UIScreen screens] objectAtIndex:1]; | |
| //CGRect extBounds = [extScreen bounds]; | |
| NSArray *modes = [extScreen availableModes]; | |
| UIScreenMode *mode1024; | |
| // Check all modes, use 1024x768 if available | |
| for (int i = 0; i < [modes count]; ++i) | |
| { | |
| UIScreenMode *mode = [modes objectAtIndex:i]; | |
| NSLog(@" modes[%d] : size = (%f, %f) ; aspect ration = %f", i, mode.size.width, mode.size.height, mode.pixelAspectRatio); | |
| if (mode.size.width == 1024 && mode.size.height == 768) | |
| mode1024 = mode; | |
| } | |
| if (nil == mode1024) { | |
| mode1024 = [modes lastObject]; | |
| } | |
| // Fix to 1024x768 or use the lastObject (highest res) | |
| [extScreen setCurrentMode:mode1024]; //[modes lastObject]]; | |
| extWindow = [[UIWindow alloc] initWithFrame:[extScreen bounds]]; | |
| [extViewController.view setFrame:[extScreen bounds]]; | |
| [extWindow addSubview:extViewController.view]; | |
| extWindow.screen = extScreen; | |
| [extWindow makeKeyAndVisible]; | |
| } | |
| // extViewController is a your VC for the external monitor | |
| // Lay it out in IB and add a VC object to your MainWindow.xib | |
| // and attach an outlet to this retained property in your | |
| // app delegate subclass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment