全面指南:解决iOS设备横屏锁定问题
iPhone 默认启用了“屏幕自动旋转”功能,通过内置的陀螺仪和加速度计感知设备方向,并自动调整屏幕方向。 但在某些场景(如游戏、视频会议、网页应用)中,用户希望固定为横屏,避免意外旋转影响体验。
这是最简单的方法,适用于所有App:
如果你是网页开发者,可通过以下方式引导用户保持横屏:
示例代码:
<style>
body { margin: 0; overflow: hidden; }
#landscape-hint {
position: fixed;
top: 0; left: 0;
width: 100vw; height: 100vh;
background: #000;
color: white;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 9999;
}
</style>
<div id="landscape-hint">
<p>请将设备旋转为横屏模式</p>
<img src="rotate-icon.png" alt="旋转提示" style="width:60px;margin-top:10px;">
</div>
<script>
function checkOrientation() {
const hint = document.getElementById('landscape-hint');
if (window.innerWidth < window.innerHeight) {
hint.style.display = 'flex';
} else {
hint.style.display = 'none';
}
}
window.addEventListener('resize', checkOrientation);
checkOrientation(); // 初始检查
</script>
部分企业级或开发者工具可通过配置文件限制设备方向,但普通用户难以操作,且受iOS安全策略限制。
建议优先使用网页提示或选择支持横屏锁定的App(如某些视频播放器)。