我正在使用 PhoneGap ExternalScreen 插件,但我对其进行了一些修改,以便能够支持多种分辨率。我从 Matt Gemmel 在 iPadVGAOutput (http://mattgemmell.com/2010/06/01/ipad-vga-output/) 上的帖子中得到了一些提示,我的代码如下所示:
- (void) toggleResolutionNSMutableArray*)arguments withDictNSMutableDictionary*)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 resultWithStatusGCommandStatus_ERROR messageAsString:WEBVIEW_UNAVAILABLE];
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
}
}
- (void)alertViewUIAlertView *)alertView clickedButtonAtIndexNSInteger)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 resultWithStatusGCommandStatus_OK messageAsString:WEBVIEW_OK];
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}
分辨率变化得很好,但内容并没有被限制在正确的尺寸内。一个例子如下:
最初加载第二个屏幕时(1920x1080),它看起来像这样:http://cl.ly/F5IV
将分辨率更改为 1280x720 后,如下所示:http://cl.ly/F41K
我对 Objective-C 比较陌生,但很快就学会了。任何有关解决我的问题和/或完全改进代码的指示都会很棒。谢谢!
安德鲁
编辑:我还想澄清一下,我没有手动设置任何正在显示的 View 和/或 CSS 的宽度/高度。 p>
由于没有人发现它,我开始深入研究Objective-C并解决了它。我必须在 alertView
方法中添加以下内容:
webView.frame = rect;
关于objective-c - iOS第二屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9727449/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |