jQuery Mobile 锁定方向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7009743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:41:10  来源:igfitidea点击:

jQuery Mobile lock orientation

jqueryjquery-mobilecordovaorientationlandscape

提问by Siggy Petersen

Hey guys i'm using phonegap and jquery mobile to build an app for an android phone. Is there a possibility to lock the orientation on one page? E.g. page "map" is loaded and the orientation is locked to "landscape" mode.

嘿伙计们,我正在使用 phonegap 和 jquery mobile 为 Android 手机构建应用程序。是否可以在一页上锁定方向?例如页面“地图”被加载并且方向被锁定为“横向”模式。

回答by guitar_freak

I have tried to modify manifest.xml and it works. Simply add android:screenOrientation="landscape" attribute to your activity tag like below:

我试图修改 manifest.xml 并且它有效。只需将 android:screenOrientation="landscape" 属性添加到您的活动标签,如下所示:

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
    <activity android:label="@string/app_name" android:name=".Phonegap_AppName"
        android:configChanges="orientation|keyboardHidden" android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

回答by andlrc

Not really i think. In xCode for iOS apps is it not possible. The only fix I can come up with, is to rotate your body or a wrapper acording to window.orientation

不是真的我认为。在 iOS 应用程序的 xCode 中是不可能的。我能想出的唯一解决办法是旋转你的身体或根据window.orientation

$(window).bind("orientationchange", function(){
    var orientation = window.orientation;
    var new_orientation = (orientation) ? 0 : 180 + orientation;
    $('body').css({
        "-webkit-transform": "rotate(" + new_orientation + "deg)"
    });
});

This is a risky way but thinks its the only way..

这是一种冒险的方式,但认为这是唯一的方式。

Hope this helps, please let me know !

希望这有帮助,请让我知道!

See: http://jsfiddle.net/aalouv/sABRQ/1/

见:http: //jsfiddle.net/aalouv/sABRQ/1/



Alternative you can bind to the window resize event.

或者,您可以绑定到窗口调整大小事件。

$(window).bind("resize", function(){
    var orientation = window.orientation;
    var new_orientation = (orientation) ? 0 : 180 + orientation;
    $('body').css({
        "-webkit-transform": "rotate(" + new_orientation + "deg)"
    });
});


I wrote this little script a while ago: It fix the multiply resize callback bug in iOS safari and the non-/late-/early-trigger(1) orientationchange bug in android.

不久前我写了这个小脚本:它修复了 iOS safari 中的多次调整大小回调错误和 android 中的 non-/late-/early-trigger(1)orientationchange 错误。

(1) Sometimes it dosn't trigger sometimes before and some times after the browser has changes width + height? Wired!

(1) 有时在浏览器更改宽度+高度之前有时不触发,有时不触发?有线!

if (!(/iphone|ipad/gi).test(navigator.appVersion)) {
    $(window).unbind("resize").bind("resize", function() {
        $(window).trigger("orientationchange");
    });
}

If not iphone or ipad you are triggering the orientationchange event on the window.

如果不是 iphone 或 ipad,您将触发窗口上的orientationchange 事件。

So when you will bind any function the the resize you do it throw orientationchange.

因此,当您绑定任何函数时,您所做的调整大小会引发orientationchange。