我可以使用Javascript或HTML锁定UIWebView的方向吗?

时间:2010-05-14 11:23:36

标签: javascript html cocoa-touch uiwebview

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

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

但是有没有办法通过HTML或Javascript在UIWebViews内容中实现相同的功能?

1 个答案:

答案 0 :(得分:1)

使用onorientationchange标记的body属性,您可以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属性是readonly。

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