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

标签 ios actionscript-3 flash air

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

这是我的代码:

        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);
        ...

您可能不会收到添加的事件,因为当连接事件监听器时,DisplayObject 可能已经在舞台上。在这种情况下,最好有条件地测试 stage 是否可用。如果是,那就继续做工作吧。否则,请等待对象被添加到舞台。

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

最后,您可能会在应用程序初始化期间收到多个调整大小事件。但是,按照您现在编写的代码的方式,它只会执行第一个操作,这可能不是“最终”大小。您可能想要重写您的调整大小处理程序,以便可以多次调用它——这看起来大部分都不错。

关于ios - 应用程序不会在 iOS 设备上调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11691028/

相关文章:

html - 如何让flash悬浮在网站上方?

iphone - 如何使用 sortUsingFunction(或 sortUsingSelector)对包含数组的对象的 NSMutableArray 进行排序

ios - 苹果手机SDK : how to distinguish between touch and drag

actionscript-3 - ActionScript 3 : How do I access the properties of the document class?

javascript - Flash播放器 "now playing list"不中断当前歌曲

html - 如何在中间放一个flash或.swf?

ios - 使用电子邮件和密码的 Google Firebase 身份验证不起作用

ios - 滚动 UITableView 时,NSManagedObject 数组变为 nil

actionscript-3 - 如何将邮政编码转换为经度和纬度?

actionscript-3 - Actionscript 3 文本字段高度