我有同样的问题。我已经在几种不同的设备上进行了测试。如果锁定屏幕需要密码,它们中的大多数实际上会崩溃或获得极大的延迟。我的解决方案允许在设备入睡后自动定向,然后在设备处于横向状态后再次禁用它。当设备处于纵向时,我隐藏了我的所有内容。仅供参考,我还没有测试所有这些代码,所以它可能会遗漏一些东西。
//Before the device goes to sleep, enable auto-orientation
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
function handleDeactivate(e:Event):void
{
stage.autoOrients = true;
//listen for the device to re-activate
e.currentTarget.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
}
//Once the device is re-activated, check the orientation.
function handleActivate(e:Event):void
{
e.currentTarget.removeEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
//if the orientation is portait, just listen for an orientation change
if (stage.stageHeight > stage.stageWidth)
{
//It makes sense that you would just use stage.setAspectRatio(StageAspectRatio.LANDSCAPE) here,
//however in my experience I've found that setting the aspect ratio here seems to cause an infinite loop of the device attempting to reset the orientation.
//Instead, I will wait for the user to change orientation, and then lock it in landscape
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
}
else
{
disableAutoOrientation();
}
}
//Check if the new orientation is landscape. If so, disable orientation changes.
function onOrientationChange():void
{
if (stage.stageWidth > stage.stageHeight)
{
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
disableAutoOrientation();
}
}
//disable the auto-orientation feature
function disableAutoOrientation():void
{
stage.autoOrients = false;
}