3 Replies Latest reply on Jan 18, 2012 9:51 AM by Sebastian Zarzycki

    orientation problem about resize

    JinWYP Level 1

      I want to show only portrait mode and use code below, it works fine to prevent  Orientation ROTATED_RIGHT and left.

      But their is a problem that the navigation bar still resize when the ROTATED_right and left,

      How can I prevent the resize of application when Orientation changed?

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" creationComplete="view1_creationCompleteHandler(event)">

          <fx:Script>

              <![CDATA[

                  import mx.events.*;

       

                  protected function view1_creationCompleteHandler(event:FlexEvent):void{

                      addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage)

                  }

       

       

                  private function _onAddedToStage(event:Event):void{

                      if(stage.autoOrients)       

                          stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);

                  }

       

                  private function _onStage_OrientationChange(event:StageOrientationEvent):void{

       

                      switch(event.afterOrientation){

       

                          case StageOrientation.DEFAULT:

                              trace('DEFAULT')

                              break;

       

                          case StageOrientation.ROTATED_RIGHT:

                              trace('ROTATED_RIGHT')

                     event.preventDefault();

                              break;

       

                          case StageOrientation.ROTATED_LEFT:

                              trace('ROTATED_LEFT')

                               event.preventDefault();

                              break;

       

                          case StageOrientation.UPSIDE_DOWN:

                              trace('UPSIDE_DOWN')

                              break;

       

                          case StageOrientation.UNKNOWN:

                              trace('UNKNOWN')

                              break;

                      }

                  }

              ]]>

          </fx:Script>   

      </s:View>

        • 1. Re: orientation problem about resize
          kraikit Level 2

          Have you tried just turning autoOrients to false and setting the stage aspect ratio to always be portrait?

           

                                                  stage.setAspectRatio(StageAspectRatio.PORTRAIT);

                                                  stage.autoOrients = false;

           

          -- Tom

          • 2. Re: orientation problem about resize
            Sebastian Zarzycki Level 1

            Tom,

             

            It's more of a generic issue. Please read my post at http://stackoverflow.com/questions/8900849/properly-preventing-orientation-change-in-flex- mobile-app

             

            In general, there are very visible issues when using event.preventDefault() on ORIENTATION_CHANGING - while the stage does not reorient, some UI parts still perform measuring and sizing, such as ViewNavigator and its components (i.e. actionbar). As a result, preventing orientation changing leads to very confusing results and basically leaving the application in undeterministic state, resulting in distorted view.

             

            The solution you've provided doesn't help much, because:

            a) turns off autoorienting, which disables the common usecase, where user just turns the device 180 degress - it's still portrait (or landscape), but the stage will not reorient then.

            b) setting aspectratio arbitrary sets stage orientation to one specific orientation (either for landscape or portrait) and kicks in the animation - this again is no good for 180 degree rotation.

             

            I've event tried to set stage autoorient = false upon enterning my view, rotating the device physically few times and then setting it back to true when exiting the view - it was always breaking application state miserably, which means there are some underlying bits that require investigation.

             

            This is one of most frustrating issues on AIR for iOS, as it pretty much renders the orientation changes unusable.

            I'm using Flex SDK 4.6 with Flash Builder 4.6 on Mac OS X Lion. Testing in debugger (the issue is visible there also) and iPad iOS 1 5.0.1