我可以阻止Safari在iPod touch或iPhone上自动旋转屏幕吗? [英] Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone?
问题描述
我们有一个离线Safari应用程序,其UI专为垂直使用而设计(像素完美).无论用户如何旋转ipod/iphone,我们都希望UI保持垂直.离线Safari应用程序可以吗?
We have an offline Safari application with UI designed for vertical use (pixel perfect). We would like the UI to stay vertical no matter what how the user rotates the ipod / iphone. Is it possible with offline Safari application?
This question is exactly the same as Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone? . Yet - the referenced question has no definite answer and has been prematurely accepted.
推荐答案
如果它需要在Safari中运行,而不是在具有嵌入式UIWebView的本机应用程序中运行,我不知道有什么方法可以阻止旋转.
I'm not aware of any way to prevent the rotation if it needs to run in Safari rather than a native app with an embedded UIWebView.
虽然您不能阻止旋转,但是可以像这样补偿它:
While you can't prevent the rotation, you can compensate for it like this:
- 使用updateorientation事件检测旋转
- 在事件处理程序中,使用window.orientation查找当前方向. (例如0、90,-90、180)
- 更新元素的类以反映当前方向,并使用-webkit-transform:rotate(-90deg)之类的样式沿相反方向旋转UI.
- 如有必要,请使用window.scrollTo(0,1);.将地址栏滚动出屏幕.
这篇关于我可以阻止Safari在iPod touch或iPhone上自动旋转屏幕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!