Properly preventing orientation change in Flex Mobile app

后端 未结 2 1285
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 05:18

Is anyone able to actually make it work properly in Flex SDK 4.6?

Here\'s a short snippet :




        
2条回答
  •  半阙折子戏
    2021-01-03 05:23

    So I had the same problem you had. I think I finally figured out the solution. Heres what I did:

    
    
    protected function tabbedviewnavigatorapplication2_applicationCompleteHandler(event:FlexEvent):void {
        stage.autoOrients=true;
        preventOrient();
    } 
    
    private function preventOrient():void { 
        if (stage.autoOrients) {
            stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);
        stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging, false, 100, true);
        }
    }
    
    private function orientationChanging(event:StageOrientationEvent):void {
        if(event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN || event.afterOrientation == StageOrientation.UNKNOWN) {
            event.preventDefault(); 
        }
    }
    

    Worth noting is that in the application complete handler I set stage.autoOrients to true because in the app.xml file I have it set to false, due to having a splash screen and not wanting users to re-orient the screen during that time. Really the only thing I did different is account for the StageOrientation.UNKNOWN and prevent whatever that would do, set the width to 1024(for the iPad screen, might be different for other tablet devices) in the main mxml file, and removed the stopimmediatepropagation. Hope this helps.

提交回复
热议问题