Я использую плагин PhoneGap ExternalScreen, но я немного изменил его, чтобы иметь возможность поддерживать несколько разрешений. Я получил несколько советов из поста Мэтта Геммела на iPadVGAOutput (http://mattgemmell.com/2010/06/01/ipad-vga-output/) Вот как выглядит мой код:
- (void) toggleResolution:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
self.callbackID = [arguments pop];
if ([[UIScreen screens] count] > 1){
externalScreen = [[[UIScreen screens] objectAtIndex:1] retain];
screenModes = [externalScreen.availableModes retain];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"External Display Size"
message:@"Choose a size for the external display."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil] autorelease];
for (UIScreenMode *mode in screenModes){
CGSize modeScreenSize = mode.size;
[alert addButtonWithTitle:[NSString stringWithFormat:@"%.0f x %.0f pixels", modeScreenSize.width, modeScreenSize.height]];
}
[alert show];
} else {
PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString:WEBVIEW_UNAVAILABLE];
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIScreenMode *desiredMode = [screenModes objectAtIndex:buttonIndex];
externalScreen.currentMode = desiredMode;
externalWindow.screen = externalScreen;
[screenModes release];
CGRect rect = CGRectZero;
rect.size = desiredMode.size;
externalWindow.frame = rect;
externalWindow.clipsToBounds = YES;
externalWindow.hidden = NO;
[externalWindow makeKeyAndVisible];
PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:WEBVIEW_OK];
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}
Разрешение меняется очень хорошо, но содержимое не ограничено правильными размерами. Пример выглядит следующим образом:
Когда изначально загружается второй экран (с разрешением 1920x1080), он выглядит следующим образом: http://cl.ly/F5IV
После изменения разрешения на 1280x720 это выглядит так: http://cl.ly/F41K
Я относительно новичок в Objective-C, но быстро его поднимаю. Любые указатели на решение моей проблемы и / или улучшение кода в целом были бы хороши. Спасибо!
Andrew
РЕДАКТИРОВАТЬ : я также хотел уточнить, я не устанавливаю вручную ширину / высоту для любого из представлений и / или CSS, которые отображаются.