我有一个AIR应用程序,我希望允许用户从60%扩展到200%。我在选项菜单中添加了一个滑块,用于控制应用程序的缩放。我对如何正确扩展整个应用程序感到困惑,需要一些帮助,我已经在这一段时间了。
此简单测试的代码如下。在每个地方添加跟踪并将侦听器放在resize事件上时,我基本上发现设置窗口的scaleX和scaleY值不会改变stage的scaleX和scaleY。但是,如果您尝试,则无法编辑这些阶段值并抛出错误。
所以,然后我尝试调整stage.stageWidth和stage.stageHeight以匹配stage.width和stage.height。但是,在这样做时,窗口的内容会再次缩放。
基本上最终发生的事情是超过100%,或者minWidth& minHeight,窗口内的组件最终剪切,部分看起来被切断,因为stage.stageWidth不像stage.width和stage.stageHeight那样宽,不像stage.height那么高。
<?xml version="1.0" encoding="utf-8"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="250" height="300"
minWidth="260" minHeight="280"
showStatusBar="false"
systemChrome="none" transparent="true"
initialize="_init()" creationComplete="_initPostCreation()"
maximizable="false" minimizable="false" xmlns:Components="assets.skins.CompOverlay.Components.*">
<fx:Declarations>
</fx:Declarations>
<s:VGroup left="2" top="2" right="2" bottom="2" gap="0">
<s:Label width="100%" textAlign="center" text="Window Scale" fontSize="14" />
<s:HGroup width="100%">
<s:HSlider id="winScale" minimum="0.6" maximum="2" width="80%" snapInterval="0.01" showDataTip="false" change="_winScale(event)" />
<s:Label width="20%" fontSize="14" textAlign="center" text="{Math.round(winScale.value*100) + '%'}"/>
</s:HGroup>
</s:VGroup>
<fx:Script>
<![CDATA[
import mx.events.ResizeEvent;
private function _init():void
{
}
private function _initPostCreation():void
{
this.addEventListener(Event.CLOSING, this._destructor);
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.addEventListener(Event.RESIZE, _onResize);
this.addEventListener(ResizeEvent.RESIZE, _onWinResize);
this.stage.align = StageAlign.TOP_LEFT;
}
private function _destructor(event:Event):void
{
this.removeEventListener(Event.CLOSING, this._destructor);
this.stage.removeEventListener(Event.RESIZE, _onResize);
this.removeEventListener(ResizeEvent.RESIZE, _onWinResize);
}
private function _winScale(event:Event):void
{
this.scaleX = event.target.value;
this.scaleY = this.scaleX;
this.width = (260*this.scaleX);
this.height = (300*this.scaleY);
trace(this.width, this.height);
trace(this.scaleX, this.scaleY);
}
private function _onResize(event:Event):void
{
trace('start resize----');
trace('stage.width = '+this.stage.width, 'stage.height = '+this.stage.height);
trace('stage.stageWidth = '+this.stage.stageWidth, 'stage.stageHeight = '+this.stage.stageHeight);
if (this.initialized) {
if (this.stage.width != this.stage.stageWidth) {
this.stage.removeEventListener(Event.RESIZE, _onResize);
this.stage.stageWidth = this.stage.width;
this.stage.stageHeight = this.stage.height;
this.stage.addEventListener(Event.RESIZE, _onResize);
}
trace('stage.width = '+this.stage.width, 'stage.height = '+this.stage.height);
trace('stage.stageWidth = '+this.stage.stageWidth, 'stage.stageHeight = '+this.stage.stageHeight);
trace('stage.scaleX = '+this.stage.scaleX, 'stage.scaleY = '+this.stage.scaleY);
}
trace('end resize----');
}
private function _onWinResize(event:ResizeEvent):void
{
trace ('window resize event');
if (this.stage.width != this.stage.stageWidth) {
event.stopPropagation();
trace('prop stopped');
}
}
]]>
</fx:Script>
</s:Window>
调整窗口大小几次会产生此跟踪输出:
start resize----
stage.width = 291.5 stage.height = 316.9
stage.stageWidth = 275 stage.stageHeight = 297
window resize event
prop stopped
window resize event
prop stopped
stage.width = 308.45 stage.height = 337.05
stage.stageWidth = 291 stage.stageHeight = 316
stage.scaleX = 1 stage.scaleY = 1 stage.scaleMode = noScale
end resize----
window resize event
prop stopped
start resize----
stage.width = 308.45 stage.height = 339.2
stage.stageWidth = 291 stage.stageHeight = 318
window resize event
prop stopped
window resize event
prop stopped
stage.width = 326.5 stage.height = 361.45
stage.stageWidth = 308 stage.stageHeight = 339
stage.scaleX = 1 stage.scaleY = 1 stage.scaleMode = noScale
end resize----
感谢您的帮助,谢谢!