PhoneGap的 - prevent旋转同时还具有自动方向启用? [英] Phonegap - Prevent Rotation While Still Having Auto-Orientation Enabled?

查看:133
本文介绍了PhoneGap的 - prevent旋转同时还具有自动方向启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新张贴别人的问题,我发现谷歌组,我有一个类似的问题:


我需要的一切是在肖像,除非在播放视频的应用程序。在iOS上,当视频播放传递给Quicktime播放器,我希望视频能够以横向模式播放。目前,该视频仅起着画像,因为它似乎继承了肖像 - 只能从PhoneGap的应用程序。我的解决方案可能是改变Phonegap.plist为自动旋转,但我希望能够使用JavaScript来赶旋转变化,除了视频播放应用程序的每一页prevent他们。这听起来是否可行?有另一种方式来强制横向方向只为应用程序的特定网页? 谢谢!


我试着旋转开启了汽车下面,都没有成功:

  $(文件)。就绪(函数(){
  document.addEventListener(orientationchange',功能(五){ÉpreventDefault();},FALSE);
});
 

解决方案

  $(窗口).bind(orientationchange,函数(){
    VAR方向= window.orientation;
    VAR new_orientation =(方向)? 0:180 +方向;
    $(身体)。CSS({
        -webkit-改造:旋转(+ new_orientation +度)
    });
});
 

这是一个危险的方式,但认为它的唯一途径。

替代可以绑定到窗口调整大小事件。

  $(窗口).bind(调整大小功能(){
    VAR方向= window.orientation;
    VAR new_orientation =(方向)? 0:180 +方向;
    $(身体)。CSS({
        -webkit-改造:旋转(+ new_orientation +度)
    });
});
 


我前一段时间写了这个小脚本:它修复机器人在iOS的Safari浏览器的多重调整回调的bug和非/迟发/早触发(1)orientationchange错误

(1)有时不到风度触发有时前,有时在浏览器之后的变化宽+高?有线!

  IF((/ iphone |!ipad的/ GI).TEST(navigator.appVersion)){
    $(窗口).unbind(调整)。绑定(调整大小功能(){
        $(窗口).trigger(orientationchange);
    });
}
 

如果没有iPhone或iPad,你的触发窗口中的orientationChange事件。

因此​​,当您将绑定的任何功能你就丢给orientationchange调整大小。

请参阅: http://jsfiddle.net/aalouv/sABRQ/1/

I'm reposting someone else's question I found on Google groups, I'm having a similar problem:


I have an application that requires everything to be in Portrait, except for when it plays a video. On iOS, when video playback is passed to the Quicktime player, I want the video to be able to be played in Landscape mode. Currently the video only plays in Portrait, since it seems to inherit the portrait - only from the phonegap application. My solution may be to change the Phonegap.plist to Auto rotate, but then I'd want to be able to use javascript to catch for rotation changes and prevent them in every page of the app except for Video playback. Does this sound feasible? Is there another way to force Landscape orientation just for a specific page of the application? Thanks!


I tried the following with Auto rotate enabled, without success:

$(document).ready(function(){
  document.addEventListener('orientationchange', function(e) { e.preventDefault(); }, false);
});

解决方案

$(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..

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.

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

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.

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

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

这篇关于PhoneGap的 - prevent旋转同时还具有自动方向启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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