开发者

Connecting ipad to external monitor

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 {    
开发者_JS百科     [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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜