views:

1719

answers:

2

I am trying to connect my ipad app to an external screen using the following (not checking the correct resolution for now - just want it up and running).

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
     [window addSubview:[navigationController view]];
     if ([[UIScreen screens] count] > 1) {
          window.screen = [[UIScreen screens] objectAtIndex:1];
     }
     [window makeKeyAndVisible];
     return YES;
}

Is this supposed to redirect everything to the external monitor? How dows it work with touches/gestures? I see in the Apple apps, the controls etc are left on the ipad screen...

+1  A: 

You need to have a separate UIWindow instance for each screen you are displaying onto (iPad, external monitor, etc.). Rather than simply set your main UIWindow's screen to the external display, you'll want to create a distinct UIWindow for that display and possibly move your views from the iPad window to the external display window. Otherwise, you won't be able to receive touch input on the iPad screen for controlling what's displayed remotely.

For example, the following code will create a new window on an external display (with externalScreen being the appropriate UIScreen instance):

CGRect externalBounds = [externalScreen bounds];
externalWindow = [[UIWindow alloc] initWithFrame:externalBounds];

UIView *backgroundView = [[UIView alloc] initWithFrame:externalBounds];
backgroundView.backgroundColor = [UIColor whiteColor];

[externalWindow addSubview:backgroundView];

[backgroundView release];

externalWindow.screen = externalScreen;
[externalWindow makeKeyAndVisible];

You will also want to watch for screen connection / disconnection events in your application, and deal with them appropriately. To do this, listen for the UIScreenDidConnectNotification and the UIScreenDidDisconnectNotification.

I have a crude example of this working within the latest code of my Molecules iPhone / iPad application, if you want to see one way of handing the external display.

Brad Larson
Thanks! I have a book-like application, so it is unclear to me how I would update the display on page turns etc...
Charlie
@Josh P. - If mirroring the display, you might be able to use posted notifications in response to gestures, with the views on the two independent windows responding to the same notification, thus keeping the displays in sync.
Brad Larson
Sorry - think I'm missing something here... Is this supposed to work automatically if I add the same root view controller to multiple windows or do I have to create multiple windows at the root view controller level and then manually make sure to forward events?
Charlie
@Josh P. - You have to manually create multiple windows and make sure that appropriate methods are called for views on all visible displays. Again, notifications are a great way of handling this.
Brad Larson
A: 

You can mirror it - Please see following link

http://stackoverflow.com/questions/2662201/ipad-vga-connector-mirror-screen-in-own-application

OptMe