代码之家  ›  专栏  ›  技术社区  ›  gargantuan

我可以用JavaScript或HTML锁定uiWebView的方向吗?

  •  4
  • gargantuan  · 技术社区  · 14 年前

    作为iPad应用程序的一部分,我正在研究一些HTML内容。我们可能需要将uiwebview的内容锁定为纵向模式,但该应用程序已经提交给苹果,我找到的唯一能实现这一点的参考是 this question 举个例子

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            return NO;
    }
    

    但是,有没有任何方法可以在使用HTML或JavaScript的uiWebView内容中实现相同的功能呢?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Community T.Woody    7 年前

    你可以 notified when the orientation changes ,通过使用 onorientationchange 性质 body 标签。

    您可以使用类似的代码 this answer's ,它监视方向的变化,然后翻转内容,使用户觉得它始终面向一个方向。

    注意,尽管你可以 prevent default behavior 在某些事件中使用如下代码:

    function touchMove(event) {
        // Prevent scrolling on this element
        event.preventDefault();
        ...
    }
    

    它没有提到阻止方向改变的任何内容:

    iPhone OS注:PreventDefault方法适用于 多点触摸 手势 输入iPhone OS 2.0及更高版本。
    [添加强调]

    另外, orientation 属性为只读。

    所以,你必须写你自己的代码,就像我上面链接的代码一样。