取决于屏幕大小,PhoneGap方向首选项 [英] Phonegap orientation preference depending on screen size

查看:136
本文介绍了取决于屏幕大小,PhoneGap方向首选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phonegap构建一个多平台应用程序。
在正常和大屏幕上的应用程序更容易在景观上使用,但在小设备(即手机或引导超小设备),它更容易使用在纵向。



我想知道是否有一种方法可以根据屏幕的大小强制使用config.xml。
我已经看过网站的答案,但我只找到具体的平台答案。但我的应用程序是一个web应用程序在HTML5中,所以我没有任何清单或plist。



这就是为什么我想使用config.xml文件。 >

编辑:



谢谢!我试过yoik插件,但我不知道如何导入插件。我试图添加:

 < gap:plugin name =net.yoik.cordova.plugins.screenorientation/& 

在我的config.xml,但似乎没有工作。



我的代码现在是这样:

  function onLoad {
document.addEventListener(deviceready,onDeviceReady,false);
}

//设备API可用
//
function onDeviceReady(){
if(window.outerWidth< 768){
screen.lockOrientation('portrait');
document.location.href ='www.site.com';
}
else {
screen.lockOrientation('landscape');
document.location.href ='www.site.com';
}
}


解决方案

I不要以为只有 config.xml 有办法做到这一点(至少对于所有平台)。如果您不一定需要使用 config.xml ,则可以使用由yoik手工插件。该插件的使用示例

  //设置为横向
screen.lockOrientation('landscape'); //或portrait

//允许用户旋转
screen.unlockOrientation();

只需将锁定放入您的 deviceReady 事件处理程序中,屏幕尺寸要求。


I am building a multi-platform app with phonegap. On normal and large screen the app is easier to use on landscape but on small devices (i.e. phone or bootstrap extra-small-device) it's easier to use in portrait.

I'd like to know if there is a way to force the orientation depending on the size of the screen using config.xml . I've looked around the site for answers but i only found specific platform answer. But my app is a web app in HTML5 so i don't have any manifest or plist.

That's why i want to use the config.xml file.

EDIT :

Thanks! I tried the yoik plugin but i can't figure out how to import the plugin. I tried to add:

<gap:plugin name="net.yoik.cordova.plugins.screenorientation" />

in my config.xml but it didn't seemed to work.

My code is now like this :

function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    //
    function onDeviceReady() {
        if (window.outerWidth < 768) {
            screen.lockOrientation('portrait');
            document.location.href = 'www.site.com';
        }
        else {
            screen.lockOrientation('landscape');
            document.location.href = 'www.site.com' ;
        }
    }

解决方案

I do not think there is a way to do this (at least for all platforms) with just config.xml. If you do not necessarily have to use the config.xml, you can use this handy plugin by yoik. Example of usage of that plugin

// set to either landscape
screen.lockOrientation('landscape'); // Or portrait

// allow user rotate
screen.unlockOrientation();

Just put the locking into your deviceReady event handler with appropriate conditionals to match the screen size requirements.

这篇关于取决于屏幕大小,PhoneGap方向首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆