0

ios6 にアップデートして以来、ベータ版の AIR 3.5 を取得する必要がありましたが、andではなく、デフォルトでStageOrientationEventのみ起動するようです。iOS 6 での向きの処理の変更について読みましたが、AIR AS3 でそれを回避する方法が見つからないようです。これが私のクイックオリエンテーションテストアプリのコードです(クイックテストのタイムラインにあるだけです):upsideDownrotatedRightrotatedLeft

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

iOS6 ではこれらのイベントが無効になっているため、AIR からイベントを取得するためにできることは何もありません。

簡単な解決策はないと思いますが、すべての加速度計データがまだそこにあるはずなので、加速度計 x、y、および z に基づいて回転がいつ変化したかを通知する独自のイベントを作成できるはずです。

于 2012-10-18T17:04:11.507 に答える
0

わかりました、加速度計の問題でこの向きを回避する方法を 1 つ見つけました。方向が変更されるたびに加速度計のデータを変更する混乱を避けるために、ステージの方向をまったく変更せず、代わりにルートを回転させて再配置し、同じ効果を与えることにしました。これは問題なく動作しますが、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 に答える