应用程序不会在iOS设备上调整大小

应用程序不会在iOS设备上调整大小

问题描述:

我正在使用AIR 3.3/Flash CS5.5编写适用于iOS和Android的应用程序。现在我遇到了问题,该应用不会在iOS设备上调整大小(在iPod touch 4上进行测试)。应用程序不会在iOS设备上调整大小

这里是我的代码:

 public function Main() { 
      this.addEventListener(Event.ADDED , Init, false, 0, true); 
     } 

     private function Init(e:Event) { 
      this.removeEventListener(Event.ADDED , Init); 

      stage.scaleMode = StageScaleMode.NO_SCALE; 
      stage.align = StageAlign.TOP_LEFT; 

      stage.addEventListener(Event.RESIZE , Resize, false, 0, true); 
     } 

     private function Resize(e:Event) { 
      stage.removeEventListener(Event.RESIZE, Resize); 

      var stageheight = Math.min(stage.fullScreenHeight, Screen.mainScreen.visibleBounds.height); 
      var stagewidth = Math.min(stage.fullScreenWidth, Screen.mainScreen.visibleBounds.width); 

      stage.stageHeight = Math.min(stagewidth, stageheight); 
      stage.stageWidth = Math.max(stagewidth, stageheight); 


      scaleFactor = stage.stageHeight/APP_ORG_HEIGHT; 

      NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE; 
     } 

它可以在Android设备上,而不是我的测试设备上。

这里我的XML设置:

<initialWindow> 
    <systemChrome>standard</systemChrome> 
    <transparent>false</transparent> 
    <visible>true</visible> 
    <fullScreen>true</fullScreen> 
    <aspectRatio>landscape</aspectRatio> 
    <renderMode>gpu</renderMode> 
    <autoOrients>false</autoOrients> 
    </initialWindow> 
    <android> 
    <manifestAdditions> 
     <![CDATA[<manifest android:installLocation="auto"> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.WAKE_LOCK"/> 
</manifest>]]> 
    </manifestAdditions> 
    </android> 
    <iPhone> 
    <InfoAdditions> 
     <![CDATA[<key>UIDeviceFamily</key><array><string>1</string></array><key>UIPrerenderedIcon</key><true/><key>UIApplicationExitsOnSuspend</key><true/>]]> 
    </InfoAdditions> 
    <requestedDisplayResolution>high</requestedDisplayResolution> 
    </iPhone> 

因为事件侦听器迷上了一次尝试更改为

public function Main() { 
     if(stage) Init(); 
     addEventListener(Event.ADDED_TO_STAGE, Init); 
    } 

    private function Init(e:Event = null) { 
     if(e != null) this.removeEventListener(Event.ADDED_TO_STAGE, Init); 
     ... 

您也许不recieveing增加的情况下,DisplayObject可能已经在舞台上。在这种情况下,最好有条件地测试是否有stage可用。如果是,那就继续做下去。否则,请等到对象已添加到舞台上。

我还会在更改舞台缩放模式和舞台对齐之前添加Event.RESIZE事件处理程序。

最后,您可能会在应用程序初始化过程中收到多个resize事件。但是现在编写代码的方式只能在第一个代码中执行,而这可能不是“最终”大小。你可能想重写你的resize处理程序,以便它可以多次调用 - 它大部分看起来没问题。

+0

谢谢你的回答,我现在就测试一下。但是,你是什么意思,“我还会在改变舞台缩放模式和舞台对齐之前添加Event.RESIZE事件处理程序。” – WolvDev 2012-07-28 06:42:42

+0

它的工作原理!非常感谢你! – WolvDev 2012-07-28 09:14:11