我正在处理一些HTML内容,作为iPad应用的一部分。我们可能需要将UIWebView的内容锁定为纵向模式,但该应用程序已经提交给Apple,我发现实现此目的的唯一参考是在this question中给出了这个示例
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
但是有没有办法通过HTML或Javascript在UIWebViews内容中实现相同的功能?
答案 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。
所以,你必须编写自己的代码,就像我上面链接的那样。