1

This question is a little strange. In Adobe AIR I am trying to combine an iPhone and an iPad version of my app into one single app. However i have a hard time dealing with orientation. I need the app on iPad to appear in landscape mode and on the iPhone it should appear in portrait mode.

Can this be done?

fideldonson
  • 581
  • 3
  • 15

3 Answers3

2

in shouldAutorotateToInterfaceOrientation do this

But don't forget to adjust view accordingly (set appropriate frames to subView)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     return UIInterfaceOrientationIsPortrait(interfaceOrientation);
 else
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • 1
    Thanks - i am specifically interested in a solution for adobe AIR (actionsript 3 or ANE). Edited my original question. – fideldonson Sep 27 '12 at 13:31
1

The first problem is detecting whether the device is an iPad or iPhone. I believe the only way to do this is by checking the device resolution (of course, you can distribute separate binaries for the different devices, but you mentioned doing this in one app).

Usually you can handle screen rotation in the XML app descriptor, e.g.:

<aspectRatio>landscape</aspectRatio>
<autoOrients>false</autoOrients>

However, since you want to do different actions depending on the device, this won't work.

An alternative that I have used in the past is to detect Orientation events and prevent the default and manually set the orientation through AS3. Here is a good example of how to do this: AS3 - iOS force landscape mode only?

Using the code sample presented there, it's just a matter of taking your device detection / screen resolution detection code and setting the screen orientation to the appropriate detection for that device (and preventing the appropriate orientation events for that device).

Community
  • 1
  • 1
Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
  • Thanks a lot - wasn't aware of the StageOrientation Class. – fideldonson Sep 27 '12 at 15:07
  • Hi Pixel Elephant Seems i have to retract my acceptance of your answer ;-) http://blogs.adobe.com/airodynamics/2012/09/28/orientation-changes-in-air/#comment-487 Do you have any idea how to achieve the effect without preventDefault() in the arsenal? – fideldonson Oct 01 '12 at 11:20
  • Aha - think i figured this out myself. I should just disable autoOrientation, and then manually set the orientation once the app has launched and i have figured out what device it is running on. I dont need preventDefault() if there are no events. – fideldonson Oct 01 '12 at 12:04
0

In case you still need it, I made the adaptation of the "force landscape mode only" to do the same with portrait only. Here's the code:

var startOrientation:String = stage.orientation;
if ( startOrientation == StageOrientation.ROTATED_RIGHT)
  {
    stage.setOrientation(StageOrientation.UPSIDE_DOWN);
  }else if(startOrientation == StageOrientation.ROTATED_LEFT){
      StageOrientation.DEFAULT;
  }
  else
  {
    stage.setOrientation(startOrientation);
  }                    

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

function orientationChangeListener(e:StageOrientationEvent)
{
   if (e.afterOrientation ==  StageOrientation.ROTATED_RIGHT || e.afterOrientation ==  StageOrientation.ROTATED_LEFT )
   {
     e.preventDefault();
   }
}
Anni
  • 1