2012-03-15 37 views
2

我正在使用PhoneGap ExternalScreen插件,但为了能够支持多种分辨率,我稍微修改了它。我从马特·盖梅尔的帖子一些技巧​​上iPadVGAOutput(http://mattgemmell.com/2010/06/01/ipad-vga-output/)这里是我的代码如下所示:iOS第二屏

- (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]]; 
} 

分辨率为改变得很好,但内容并没有被限制在正确的维度内。一个例子如下:

当第二屏幕最初加载(在1920×1080),它看起来像这样:http://cl.ly/F5IV

改变分辨率为1280×720后,它看起来像这样:http://cl.ly/F41K

我对于Objective-C来说相对来说比较新,但我很快就会选择它。任何解决我的问题和/或完善代码的指针都会很棒。谢谢!

安德鲁

编辑:我也想澄清,我没有手动设置任何的正在显示的意见和/或CSS任何宽度/高度。

+0

你是否被迫使用辅助屏幕?你可以摆脱iOS镜像吗?我发现与第二个屏幕相比,镜像提供了更好的整体体验。它可能不符合您的要求,但值得评估。 – Alan 2012-03-15 20:17:38

+0

Alan,不幸的是我们被迫使用第二个屏幕,因为第二个屏幕的比例是16:9,iPad是4:3。我们基本上是镜像,但除非您知道一种方法来在没有手动编写第二个屏幕代码的情况下摆脱黑条,否则我们会卡住! :( – andrewpthorp 2012-03-15 20:26:12

+0

Ahh ipad ...废话它在iPhone4的环境下工作得很好我只是在30英寸的显示器上查看了我们的ipad应用程序,并且它有黑色的条形码 – Alan 2012-03-15 20:36:08

回答

1

由于没有人发现它,我开始深入Objective-C并解决它。我不得不添加下面的alertView方法:

webView.frame = rect; 
1

由于您的解决方案并没有为我工作,我会把我的解决了这个在这里。虽然屏幕尺寸正确,但我也在屏幕上看到了黑条。我只是不得不设置

[externScreen setOverscanCompensation: UIScreenOverscanCompensationInsetApplicationFrame]; 

和酒吧都走了。

相关问题