当我在 Flex 容器中有一个对象(绝对定位)并将其比例值设置得非常低,然后旋转它,随着比例的减小,旋转变得“更不稳定”。我包括重现问题的代码。您可以点击“向上箭头”以缩小对象(“向下”以放大)和“向上”以增加对象的大小,以便您仍然可以看到它。缩小后,您可以使用“左”和“右”来旋转它。请注意,当对象未按比例缩小时,它会干净地旋转,但如果您将对象按比例缩小(同时增加对象的大小以便您仍然可以看到它),则旋转会变得不稳定。有任何想法吗?
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:test="com.test.*"
resize="onResize()" addedToStage="onStart()" removedFromStage="onEnd()">
<fx:Script>
<![CDATA[
[Bindable]
private var _rotation:Number = 0;
[Bindable]
private var _scale:Number = 1;
[Bindable]
private var _blockSize:Number = 100;
protected function onStart():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
protected function onEnd():void {
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
protected function onResize():void {
if (Layer) {
Layer.x = width/2
Layer.y = height/2;
}
}
protected function onKeyDown(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.LEFT) {
Layer.rotation += -1;
}
if (event.keyCode == Keyboard.RIGHT) {
Layer.rotation += 1;
}
if (event.keyCode == Keyboard.UP) {
Layer.scaleX = Layer.scaleY = (Layer.scaleX / 2);
}
if (event.keyCode == Keyboard.DOWN) {
Layer.scaleX = Layer.scaleY = (Layer.scaleX * 2);
}
if (event.keyCode == Keyboard.PAGE_UP) {
_blockSize *=2;
}
if (event.keyCode == Keyboard.PAGE_DOWN) {
_blockSize /=2;
}
this._rotation = Layer.rotation;
this._scale = Layer.scaleX;
}
]]>
</fx:Script>
<s:SkinnableContainer id="Layer">
<test:RotatedComponent width="{_blockSize}" height="{_blockSize}"/>
</s:SkinnableContainer>
<s:Label x="10" y="10" text="Rotation: {_rotation}"/>
<s:Label x="10" y="30" text="Scale: {_scale}"/>
<s:Label x="10" y="50" text="Block: {_blockSize}"/>
</s:WindowedApplication>
RotatedComponent.mxml 的代码
package com.test {
import mx.core.UIComponent;
public class RotatedComponent extends UIComponent {
public function RotatedComponent() {
super();
}
override public function set width(value:Number):void {
super.width = value;
this.x = - (width/2);
}
override public function set height(value:Number):void {
super.height = value;
this.y = - (height/2);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
graphics.lineStyle(2, 0x333333);
graphics.beginFill(0x660000);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.endFill();
graphics.lineStyle(2, 0xffffff);
graphics.drawCircle(unscaledWidth/2, unscaledHeight/2, 5);
}
}
}
谢谢!德里克