问题
Intro: I have a AIR Mobile AS3 Project, where I want to receive all Orientation events onChange, but never actually let the device rotate the Screen (I do the necessary altering myself). So I set the autoOrients=true (needed to get any Orientation events) and try to prevent the device rotation by e.preventDefault (now deprecated on iOS).
You can download a FlashDeveloper Project with the problem here. Upload it to an Android device and let me know if you get StageOrientationEvents when rotating back to Default (Portrait).
The three other Orientations fire just fine and I receive from afterOrientation:
- rotatedRight
- rotatedLeft
- upsideDown
But when rotating back to the initial Position (Protrait) StageOrientationEvent does not fire.
My application.xml ist like this:
<visible>true</visible>
<fullScreen>false</fullScreen>
<autoOrients>true</autoOrients>
<aspectRatio>any</aspectRatio>
<resizable>true</resizable>
Interesting tho is, that when I start my App on Mobile in Landscape, I receive:
- rotatedLeft
- upsideDown
- default
So again, when rotating to the initial Position (in this case rotatedRight) StageOrientationEvent ist not firing. The Initial Position does not give a StageOrientationEvent.
This is my listener:
private function onOrientationChanging(e:StageOrientationEvent):void {
e.preventDefault();
ui.console.field.text += "\nORIENTATION_CHANGING "+e.afterOrientation;
var rot:Number = 0;
switch (e.afterOrientation){
case "rotatedRight":
rot = 90;
break;
case "rotatedLeft":
rot = -90;;
break;
case "upsideDown":
rot = 180;;
break;
default:
rot = 0;
break;
}
TweenMax.to(ui.console.orient, 3, { shortRotation:{rotationZ:rot}, ease:Elastic.easeOut } );
}
I even tried removing the e.preventDefault() in the hope that this somehow not only disabled the auto-rotation of the app but also somehow might prevent the firing of the default rotation. But that is not the case.
Any ideas?
Specs:
FlashDevelop 5.0
SDK Air17.0 + FLex 4.6.0
Android Nexus 5 Android 5.1.1
来源:https://stackoverflow.com/questions/30649092/stageorientationevent-is-not-dispatching-on-default-orientation-portrait