Search This Blog

2012-10-19

Stage Orientation, iOS 6, and AIR 3.3+

Good stuff to be aware of if you're developing with the latest from Apple and Adobe:

This post on Varun Bhatia's AIR-o-Dynamics blog explains how iOS 6 doesn't send auto-orientation callbacks anymore, which means AS3's StageOrientationEvent listeners are worthless on the iPhone 5 and preventDefault() no longer works for ORIENTATION_CHANGING events.

Anyway, let's say you've designed your app with a landscape aspect ratio in mind, and let's also say you want your user to be able to hold the device in either the ROTATED_RIGHT or the ROTATED_LEFT position.

Previously you may have written an entire class full of listeners and preventDefault() handlers... but since iOS 6, that class doesn't work anymore. Turns out that since AIR 3.3 there's a much better easier way to do it.

In the application descriptor .xml, set the following:

<aspectRatio>landscape<aspectRatio>
<autoOrients>true</autoOrients>

Then, in your AS3 code, call:

stage.setAspectRatio(StageAspectRatio.LANDSCAPE);

Piece of cake! Works like a charm on my iPhone 4 with iOS 6 and AIR 3.5 (beta)... please comment if your mileage varies. Here are those links again, which I highly recommend for further explanation:

StageAspectRatio Enhancements in AIR 3.3
Orientation Changes in AIR 3.5

No comments:

Post a Comment