0

自从更新到 ios6,因此必须获得 beta AIR 3.5,它似乎是StageOrientationEvent唯一触发upsideDown和默认的,rotatedRight不再是rotatedLeft。我已经阅读了有关 ios6 中方向处理的更改,但我似乎无法为 AIR AS3 找到解决方法。这是我的快速定向测试应用程序的代码(只是在快速测试的时间线上):

stage.autoOrients = true
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChange);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);

function orientationChange(e:StageOrientationEvent):void{
    var t:TraceOnStage = new TraceOnStage(stage ,"----------------");
    t= new TraceOnStage(stage, "orientationChange before: " + e.beforeOrientation + stage.orientation);     
    t = new TraceOnStage(stage, "orientationChange after: " + e.afterOrientation + stage.orientation);
}

function orientationChanging(e:StageOrientationEvent):void{
    var t:TraceOnStage = new TraceOnStage(stage ,"----------------");
    t = new TraceOnStage(stage, "orientationChanging before: " + e.beforeOrientation + stage.orientation);      
    t = new TraceOnStage(stage, "orientationChanging after: " + e.afterOrientation + stage.orientation);
}

在 iPad 上它只跟踪颠倒和默认情况,它工作正常,直到 ios6。我有一系列需要定向的应用程序即将完成,客户正在等待然后这发生了!任何想法或帮助将不胜感激。

4

3 回答 3

1

尝试删除应用程序描述符 xml 中的 (aspectRatio) 部分 - 方向更改再次在各个方向起作用。

于 2012-11-10T01:12:54.370 回答
0

好的,我找到了一种解决加速度计问题的方法。为了避免每次改变方向时改变加速度计数据的混乱,我决定尝试完全不改变舞台方向,而是旋转和重新定位根以产生相同的效果。它运行良好,但请注意应用程序中使用 localToGlobal 或舞台 mouseX 和 mouseY 的任何代码都需要额外的代码行才能使用根作为定位参考。这是我写的整个课程。它处于第一个工作阶段,因此欢迎提出任何改进意见!

import flash.sensors.Accelerometer;
import flash.events.AccelerometerEvent;
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.display.StageOrientation;
import flash.display.Stage;
import flash.display.DisplayObject;
import flash.utils.setInterval;
import flash.utils.clearInterval;


public class AcceleroOrientator extends EventDispatcher {

    public static const ORIENTATION_CHANGE:String = "orientationChange";

    public var currentOrientation:String = StageOrientation.DEFAULT

    private var firstCheckOrientation:String = StageOrientation.DEFAULT;

    private var theRoot:DisplayObject;

    private var myConst:Number = Math.sin(Math.PI/4);

    private var accl:Accelerometer;

    private var inter:int;

    private var inter2:int;

    private var currenAcceleromResult:String;

    private var checkFrequency:int = 500;




    public function AcceleroOrientator(tRoot:DisplayObject) {
        if (Accelerometer.isSupported) {
            accl = new Accelerometer();
            accl.setRequestedUpdateInterval(100);
        } else {
            trace("Accelerometer feature not supported!!");
        }
        theRoot = tRoot;
        theRoot.stage.autoOrients = false;
    }


    public function set active(val:Boolean):void {
        if (inter2){
            clearInterval(inter2);
        }
        if (val==true) {
            if (! accl.hasEventListener(AccelerometerEvent.UPDATE)){
                accl.addEventListener(AccelerometerEvent.UPDATE, getAcceleromOrientation);
            }
            currentOrientation = currenAcceleromResult;
            inter2 = setInterval(checkOrientation, checkFrequency);
        } else {
            if (accl.hasEventListener(AccelerometerEvent.UPDATE)){
                accl.removeEventListener(AccelerometerEvent.UPDATE, getAcceleromOrientation);
            }
        }

    }


    private function checkOrientation():void {
        firstCheckOrientation = currenAcceleromResult;
        if (inter){
            clearInterval(inter);
        }
        if (currentOrientation != firstCheckOrientation) {
            inter = setInterval(confirmOrientation, checkFrequency/3);
        }
    }


    private function confirmOrientation():void{
        if (inter){
            clearInterval(inter);
        }
        var secondCheckOrientation = currenAcceleromResult;
        if (firstCheckOrientation == secondCheckOrientation){
            currentOrientation = firstCheckOrientation;
            doRootRotation();
            dispatchEvent(new Event(ORIENTATION_CHANGE));
        }
    }


    private function doRootRotation():void{

        if (currentOrientation == StageOrientation.ROTATED_LEFT){
            theRoot.rotation = 90;
            theRoot.x = theRoot.stage.stageWidth;
            theRoot.y = 0;
        } else if (currentOrientation == StageOrientation.DEFAULT) {
            theRoot.rotation = 0;
            theRoot.x = 0;
            theRoot.y = 0;
        } else if (currentOrientation == StageOrientation.ROTATED_RIGHT) {
            theRoot.rotation = -90;
            theRoot.x = 0;
            theRoot.y = theRoot.stage.stageHeight;
        } else if (currentOrientation == StageOrientation.UPSIDE_DOWN) {
            theRoot.rotation = 180;
            theRoot.x = theRoot.stage.stageWidth;
            theRoot.y = theRoot.stage.stageHeight;
        }

    }


    private function getAcceleromOrientation(e:AccelerometerEvent):void{

        if (Math.abs(e.accelerationZ) > myConst){
            return;
        }

        if (e.accelerationX > 0 && e.accelerationY >  -  myConst && e.accelerationY < myConst) {
            currenAcceleromResult =  StageOrientation.ROTATED_LEFT;
        } else if ( e.accelerationY >= myConst) {
            currenAcceleromResult =  StageOrientation.DEFAULT;
        } else if (e.accelerationX < 0 && e.accelerationY > -myConst && e.accelerationY < myConst) {
            currenAcceleromResult =  StageOrientation.ROTATED_RIGHT;
        } else if (e.accelerationY <= myConst) {
            currenAcceleromResult =  StageOrientation.UPSIDE_DOWN;
        } else {
            currenAcceleromResult =  StageOrientation.UNKNOWN;
        }

    }




}
于 2012-10-25T04:08:03.537 回答
0

由于 iOS6 已禁用这些事件,因此您无法从 AIR 中获取它们。

我不认为有任何简单的解决方案,但由于所有加速度计数据应该仍然存在,您应该能够构建自己的事件,根据加速度计 x、y 和 z 告诉您旋转何时发生变化。

于 2012-10-18T17:04:11.507 回答