【问题标题】:Can I lock a UIWebView's orientation with Javascript or HTML?我可以使用 Javascript 或 HTML 锁定 UIWebView 的方向吗?
【发布时间】:2010-05-14 11:23:35
【问题描述】:

我正在处理一些 HTML 内容作为 iPad 应用程序的一部分。我们可能需要将 UIWebView 的内容锁定为纵向模式,但该应用程序已经提交给 Apple,我发现实现这一点的唯一参考是 this question,它给出了这个示例

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

但是有没有什么方法可以在 UIWebViews 内容中使用 HTML 或 Javascript 实现相同的功能?

【问题讨论】:

    标签: javascript html cocoa-touch uiwebview


    【解决方案1】:

    通过使用body 标记的onorientationchange 属性,您可以成为notified when the orientation changes

    您可以使用类似于this answer's 的代码,它会监控方向变化,然后翻转内容,使其在用户看来始终面向一个方向。

    请注意,虽然您可以使用如下代码 prevent default behavior 处理某些事件:

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

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

    iPhone OS 注意:preventDefault 方法适用于 iPhone OS 2.0 及更高版本中的多点触控手势输入。
    [强调]

    此外,orientation 属性是只读的。

    因此,您必须编写自己的代码,就像我上面链接的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 2010-10-11
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      相关资源
      最近更新 更多