• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

objective-c - iOS第二屏

[复制链接]
菜鸟教程小白 发表于 2022-12-11 22:07:34 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 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>



Best Answer-推荐答案


由于没有人发现它,我开始深入研究Objective-C并解决了它。我必须在 alertView 方法中添加以下内容:

webView.frame = rect;

关于objective-c - iOS第二屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9727449/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap