我正在使用PhoneGap ExternalScreen插件,但我稍微修改了它以支持多种分辨率。我从Matt Gemmel在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比较新,但我很快就会把它拿出来。关于解决我的问题和/或完全改进代码的任何指示都会很棒。谢谢!
安德鲁
编辑:我还想澄清一下,我没有在任何正在显示的视图和/或CSS上手动设置任何宽度/高度。
答案 0 :(得分:1)
由于没有人发现它,我开始深入研究Objective-C并解决了它。我必须在alertView
方法中添加以下内容:
webView.frame = rect;
答案 1 :(得分:1)
由于您的解决方案对我不起作用,我会在此处提出解决方案。尽管屏幕尺寸被检测到正确,但我还是看到了视图周围的黑条。我只需要设置
[externScreen setOverscanCompensation: UIScreenOverscanCompensationInsetApplicationFrame];
并且酒吧都没了。