Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 锁定适用于iPhone iPad的webapp的方向_Javascript_Iphone_Ipad_Safari_Web Applications - Fatal编程技术网

Javascript 锁定适用于iPhone iPad的webapp的方向

Javascript 锁定适用于iPhone iPad的webapp的方向,javascript,iphone,ipad,safari,web-applications,Javascript,Iphone,Ipad,Safari,Web Applications,可能重复: 我正在努力锁定网络应用的方向。例如,您希望站点永久位于方向视图中 感谢您的建议。使用UIViewController-BOOLshouldAutorotateToInterfaceOrientation的此方法:UIInterfaceOrientation InterfaceOrientation 并测试interfaceOrientation是否等于所需的UIInterfaceOrientation,在这种情况下,返回YES else NO typedef enum { U

可能重复:

我正在努力锁定网络应用的方向。例如,您希望站点永久位于方向视图中


感谢您的建议。

使用UIViewController-BOOLshouldAutorotateToInterfaceOrientation的此方法:UIInterfaceOrientation InterfaceOrientation 并测试interfaceOrientation是否等于所需的UIInterfaceOrientation,在这种情况下,返回YES else NO

typedef enum {
   UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
   UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
   UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
   UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;
我制作了keep函数,该函数以您希望保持90/180/-90/0的方向为参数:

function keep(nbre)
{
    var preventer,deviceW=screen.width,deviceH=screen.height;
    function set()//I put all the content of the body in a container named 'preventer' so that I can turn it (I can't turn the <body>)
    {
        var body=document.getElementsByTagName("body")[0];
        preventer=document.createElement("div");
        preventer.innerHTML=body.innerHTML;
        preventer.style.position="absolute";
        body.innerHTML="";
        modify();
        document.body.appendChild(preventer);
    }
    function modify()
    {
        function sign(x,y){return(x>0?1:(x<0?-1:y));}//Return the sign or y if 0
        window.scrollTo(0,0);
        var o=window.orientation,width,height,transformorigin,transform="rotate(",top,left;
        if(!(nbre%180))//Multiple of 180 : 180, 360...
        {
            if(!(o%180))//Also multiple of 180
            {
                width=deviceW;//Width and height ar those of the device
                height=deviceH-20;//-20 because of the status bar
            }
            else
            {
                width=deviceW-20;
                height=deviceH;
            }
        }
        else
        {
            if(!(o%180))
            {
                width=deviceH-20;
                heigth=deviceW;
            }
            else
            {
                width=deviceH;
                height=deviceW-20;
            }
        }
        if(Math.abs(nbre%180)==Math.abs(o%180))//If it's 90 and 90 or 90 and -90 or 180 and 180...
        {
            transformorigin="50% 50%";//The origin of rotation must be the center of the div
        }
        else
        {
            transformorigin="0px 0px";
        }

        if(!nbre)//0
        {
            if(!(o%180))//180, 360...
            {
                transform=o;
            }
            else
            {
                transform=-o;
            }
        }
        else
        {
            if(nbre==90)
            {
                transform=o-(o*2-90);//0=>90 90=>0 180=>-90 -90=>180
            }
            else
            {
                if(nbre==-90)
                {
                    if(sign(o,-1)==-1)
                    {
                        transform=o-sign(o,1)*90;
                    }
                    else
                    {
                        transform=o-180+sign(o-180,1)*90;
                    }
                }
                else
                {
                    if(!(o%180))
                    {
                        transform=o-sign(o,-1)*180;
                    }
                    else
                    {
                        transform=o;
                    }
                }
            }
        }
        transform+="deg)";

        if(Math.abs(nbre)%180==Math.abs(o)%180)
        {
            top=0;
            left=0;
        }
        else
        {
            if(nbre==0&&o==90||nbre==180&&o==-90)
            {
                top=deviceW-20;
                left=0;
            }
            else
            {
                if(nbre==0&&o==-90||nbre==180&&o==90)
                {
                    top=0;
                    left=deviceH;
                }
                else
                {
                    if(nbre==-90&&o==0||nbre==90&&o==180)
                    {
                        top=deviceH-20;
                        left=0;
                    }
                    else
                    {
                        top=0;
                        left=deviceW;
                    }
                }
            }
        }
        preventer.style.webkitTransform=transform;
        preventer.style.webkitTransformOrigin=transformorigin;
        preventer.style.width=width+"px";
        preventer.style.height=height+"px";
        preventer.style.top=top+"px";
        preventer.style.left=left+"px";
    }
    window.addEventListener("orientationchange",modify,false);
    window.addEventListener("load",set,false);
}
以下是一个较小的版本:

function keep(nbre)
{
    var preventer,deviceW=screen.width,deviceH=screen.height;
    function set()
    {
        var body=document.getElementsByTagName("body")[0];
        preventer=document.createElement("div");
        preventer.innerHTML=body.innerHTML;
        preventer.style.position="absolute";
        body.innerHTML="";
        modify();
        document.body.appendChild(preventer);
    }
    function modify()
    {
        function sign(x,y){return(x>0?1:(x<0?-1:y));}
        window.scrollTo(0,0);
        var o=window.orientation,s=!(nbre%180)?(!(o%180)?[deviceW,deviceH-20]:[deviceW-20,deviceH]):(!(o%180)?[deviceH-20,deviceW]:[deviceH,deviceW-20]),t=[Math.abs(nbre%180)==Math.abs(o%180)?"50% 50%":"0px 0px","rotate("+(!nbre?(!(o%180)?o:-o):((nbre==90)?o-(o*2-90):((nbre==-90)?(sign(o,-1)==-1?o-sign(o,1)*90:o-180+sign(o-180,1)*90):(!(o%180)?o-sign(o,-1)*180:o))))+"deg)"],p=Math.abs(nbre)%180==Math.abs(o)%180?[0,0]:(nbre==0&&o==90||nbre==180&&o==-90?[deviceW-20,0]:(nbre==0&&o==-90||nbre==180&&o==90?[0,deviceH]:(nbre==-90&&o==0||nbre==90&&o==180?[deviceH-20,0]:[0,deviceW])));
        preventer.style.webkitTransform=t[1];
        preventer.style.webkitTransformOrigin=t[0];
        preventer.style.width=s[0]+"px";
        preventer.style.height=s[1]+"px";
        preventer.style.top=p[0]+"px";
        preventer.style.left=p[1]+"px";
    }
    window.addEventListener("orientationchange",modify,false);
    window.addEventListener("load",set,false);
}
那么如果你写keep90;在代码中的任何地方,当您打开iPod时,屏幕将保持在左侧


注:只有当应用程序保存到主屏幕时,它才能在全屏视图下工作。

是的,我想这里也已经讨论过了:这个问题似乎是特定于Web应用程序的,所以本机代码不是一个选项。有没有办法更清楚地说明这一部分?var o=窗口。方向,s=!丁腈橡胶%180。。。506更多的字符。。。[deviceH-20,0]:[0,deviceW];我添加了一个解释版本。放一个大的else的奇怪方式是因为我把它转换成了a?b:c形式,它是这样组织的。如果你听不懂一句话,就问我。