forked from schacon/ShowOffPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowOffPadAppDelegate.m
73 lines (56 loc) · 2.05 KB
/
ShowOffPadAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// ShowOffPadAppDelegate.m
// ShowOffPad
//
// Created by Scott Chacon on 5/5/10.
// Copyright GitHub 2010. All rights reserved.
//
#import "ShowOffPadAppDelegate.h"
#import "ShowOffPadViewController.h"
#import "ShowOffPadPresentController.h"
@implementation ShowOffPadAppDelegate
@synthesize window, extWindow;
@synthesize viewController, presentController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);
presentController = [[ShowOffPadPresentController alloc]
initWithNibName:@"ShowOffPadPresentController"
bundle:nil];
viewController.extDisplay = presentController;
if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
{
UIScreenMode *bestScreenMode;
BOOL screenChoosen = FALSE;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if (!screenChoosen) {
bestScreenMode = current;
}
if (current.size.width == 1024.0) {
bestScreenMode = current;
}
}
//Now we have the highest mode. Turn the external display to use that mode.
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = bestScreenMode;
//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
//extWindow = [[UIWindow alloc] init];
extWindow = [[UIWindow alloc] initWithFrame:[external bounds]];
[extWindow addSubview:presentController.view];
[extWindow makeKeyAndVisible];
extWindow.screen = external;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[presentController release];
[window release];
[extWindow release];
[super dealloc];
}
@end