如何在 ONSEN-UI 中阻止横向模式?
How to block Landscape Orientation mode in ONSEN-UI?
我正在开发一个 ONSEN 应用程序,我想在其中只允许设备使用纵向模式并关闭横向模式。怎么做?
Onsen UI 不提供禁用横向模式的功能,因为此功能取决于平台。您可以做的是,首先使用 ons.orientation
检测方向,然后使用 ons.platform
检测平台,并应用默认平台指令来阻止横向模式。
一个更简单的解决方案可能是在横向旋转视图后将视图旋转回纵向。
window.addEventListener('orientationchange', function ()
{
if (window.innerHeight > window.innerWidth)
{
document.getElementsByTagName('body').style.transform = "rotate(90deg)";
}
});
我正在开发一个 ONSEN 应用程序,我想在其中只允许设备使用纵向模式并关闭横向模式。怎么做?
Onsen UI 不提供禁用横向模式的功能,因为此功能取决于平台。您可以做的是,首先使用 ons.orientation
检测方向,然后使用 ons.platform
检测平台,并应用默认平台指令来阻止横向模式。
一个更简单的解决方案可能是在横向旋转视图后将视图旋转回纵向。
window.addEventListener('orientationchange', function ()
{
if (window.innerHeight > window.innerWidth)
{
document.getElementsByTagName('body').style.transform = "rotate(90deg)";
}
});