Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone?

烈酒焚心 提交于 2019-12-07 16:23:29

问题


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.


回答1:


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:

  1. Detect the rotation using the updateorientation event
  2. In your event handler, find the current orientation using window.orientation. (e.g. 0, 90, -90, 180)
  3. Update the class of your element to reflect the current orientation, and use styles like -webkit-transform:rotate(-90deg) to rotate your UI in the opposite direction.
  4. If necessary, use window.scrollTo(0, 1); to scroll the address bar off the screen.


来源:https://stackoverflow.com/questions/2601282/can-i-prevent-mobile-safari-from-auto-rotating-the-screen-on-ipod-touch-or-iphon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!