2012-03-15 44 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]; 

和酒吧都走了。

相關問題