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.